![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
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; } |
|
|
|
|
|
#2 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|