Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2007, 4:59 AM   #1
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
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;
}
357mag is offline   Reply With Quote
Old Apr 18th, 2007, 5:27 AM   #2
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4 Klarre is on a distinguished road
http://www.programmingforums.org/for...o-cin-get.html
__________________
http://www.klarre.se
Klarre is online now   Reply With Quote
Old Apr 18th, 2007, 5:59 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Apr 18th, 2007, 7:19 AM   #4
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
Seems like DaWei hit two pidgeons in one shot.

Here is an explanation.
__________________
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.
pegasus001 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC