Friday, July 31, 2009

Wats wrong with this?

i'm using the c++ compiler dev-c++ and when i put this in it compiles and it lets me enter the # but it shuts off 2 fast 4 me 2 see the double. using namespace std;





int main()


{


int i;


cout%26lt;%26lt;"please enter a integer value: ";


cin %26gt;%26gt; i;


cout%26lt;%26lt;"the value you entered is " %26lt;%26lt;i;


cout%26lt;%26lt;"and its double is "%26lt;%26lt;i*2%26lt;%26lt;".\n";


cin.get();


return 0;


}





wat am i doing wrong?

Wats wrong with this?
You're not running this from the command prompt so the program exits straight away.





Try this and it will wait for you to enter something after you see the double.:





int main()


{


int i;


cout%26lt;%26lt;"please enter a integer value: ";


cin %26gt;%26gt; i;


cout%26lt;%26lt;"the value you entered is " %26lt;%26lt;i;


cout%26lt;%26lt;"and its double is "%26lt;%26lt;i*2%26lt;%26lt;".\n";


cout%26lt;%26lt;"\nType anything to exit\n";


cin %26gt;%26gt; i;


return 0;


}
Reply:it sounds like you're building this in windows as a console app and running it by clicking the icon. my first advice is to not run console apps like this. open up a command window (start-%26gt;run: type cmd) and run the file manually.





what is probably happening here is that the cin.get() is grabbing something off the buffer (probably the enter/return key) and the function is returning as fast as it can.





change the cin.get() to cin %26gt;%26gt; blah and it should hold up there a little longer.

flowers gifts

No comments:

Post a Comment