Home › Forums › C Programming › Result is only TRUE.
- This topic has 1 reply, 2 voices, and was last updated 16 years, 8 months ago by niklaesh.
Viewing 1 reply thread
- AuthorPosts
- April 11, 2008 at 9:18 am #2090jeraidParticipant
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:
1234567891011121314151617181920212223242526272829<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.
- April 12, 2008 at 3:48 am #3377niklaeshParticipant
@Gramdtante wrote:
123void 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
1234void showResult(int res){<br />cout<<"The result is "<<res<< endl;<br />}<br />
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.