Saturday, May 22, 2010

Newb C++ Problem i cannot solve, plz HELP beginner?

#include%26lt;iostream%26gt;


using namespace std;





int main ()


{


int x;


int y;





cout %26lt;%26lt; "Enter number: " ;


cin %26gt;%26gt; x ;





cout %26lt;%26lt; " Your Number is " %26lt;%26lt; x %26lt;%26lt; endl;


cout %26lt;%26lt; "Good, Now choose another: ";


cin %26gt;%26gt; y;


cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; cout %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt;endl;





system ("pause");


return 0 ;


}





it prints :





Enter number: 5


Your Number is 5


Good, Now choose another 9


the equation will be 90x4433c4 plus 5


Press any key to continue . . .








Now i want to know why does it show "90x4433c4" and not "9"

Newb C++ Problem i cannot solve, plz HELP beginner?
Though you did not mention what do u mean by equation; whether you want to add both numbers...





The problem I see is: remove the cout which is appearing after y. In shot remove "%26lt;%26lt; cout" which is appearing after y. Your statement should appear like this:





cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt;endl;








And if u want to add x and y then you need to do like this





cout %26lt;%26lt; " the equation will be " %26lt;%26lt; y %26lt;%26lt; " plus " %26lt;%26lt; x %26lt;%26lt; "=" %26lt;%26lt; x + y;
Reply:The 9 prints correctly





the 0x4433c4 that follows it is the hexadecimal for of the cout statement, as you only need "cout" once, it is actualy outputting the cout, if that makes sense
Reply:Remove the %26lt;%26lt; cout in the middle of the line.


You are printing out the address to the cout method.
Reply:You get some expert help from http://expert.ccietutorial.com/
Reply:Hi


The Number which you see in the consol is the address of the cout object (because 'cout' is an object from the ostream class)


and you have to remove the 'cout' to get the right number





Another thing i see in our code


you have to initialized your attributes


int x=0;


Not to make problems in other times

sweet pea

No comments:

Post a Comment