![]() |
How would I do this?
I'm using Visual Studio 2005. I'm writing a program that inputs two integers from the user and adds them together and outputs their sum. That much I have. But I would like to add the line "Press any key to continue". And then when I hit like the spacebar the console window will close. I believe Visual C++ 6 had it set up this way with that Press any key to continue output to the console window, and I like it so I'd like to add that to the bottom of the console window. The way it's working now the console window will close if I hit the Enter key, but it won't close if I hit the Spacebar or any other key. Here is my program:
#include "stdafx.h" #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int integer1, integer2, sum; cout << "Enter first integer\n"; cin >> integer1; cout << "Enter second integer\n"; cin >> integer2; sum = integer1 + integer2; cout << "The sum is " << sum << endl; cin.get(); cin.get(); return 0; } |
|
Please be polite enough to read the forum's rules/FAQ, particularly with respect to the use of code tags.
The answer is: you have crap in the stream from the previous input operations. Clear it out. See cin.ignore. |
|
| All times are GMT -5. The time now is 2:24 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC