- This topic has 1 reply, 2 voices, and was last updated 14 years, 9 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.
Home › Forums › C Programming › Result is only TRUE.
Hello.
I’m abit of a newbie at C++ programming.
I’m trying to create a simple program, that can just multiply x and y, that you enter.
But when I run the program, everything is fine. Then, when I’ve entered the two numbers, the only result that shows up is 1, which must mean that it doesn’t actually retrieve the result, but just says TRUE.
If anyone would be able to help me with this problem, I’d appreciate it.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<br /> #include <conio.h><br /> #include <iostream><br /> #pragma hdrstop<br /> <br /> using namespace std;<br /> int multiply (int, int);<br /> void showResult(int);<br /> int main(int argc, char **argv);<br /> int main (int, char**){<br /> int x, y, result;<br /> cout<<"Enter the first value:";<br /> cin>> x;<br /> cout<<"Enter the second value: ";<br /> cin>> y;result = multiply(x, y);<br /> showResult(result);<br /> cout<< "Press any key to continue...";<br /> getch();<br /> return 0;<br /> }<br /> <br /> int multiply(int x, int y){<br /> return x * y;<br /> }<br /> <br /> void showResult(int res){<br /> cout<<"The result is "<<showresult << endl;<br></showresult> }<br /> </iostream> |
Thank you, in advance.
@Gramdtante wrote:
123 void showResult(int res){ <br />cout<<"The result is "<<showResult << endl;<br />}
Hello,you are not trying to print the result, as you can see variable res stores the result of the multiplication, but your are printing the result anywhere….You showResult function should look like
1 2 3 4 |
void showResult(int res){<br /> cout<<"The result is "<<res<< endl;<br /> }<br /> |