C++ question

Kur

Senior member
Feb 19, 2005
677
0
0
I just upgraded to VS2008 and it seems I keep getting this very annoying problem, whenever I write a program it works, however at the end when it outputs the answer I can barely see the output but the window instantly closes.

Any ideas?

Edit. my code and output info.

// ******************************************************
//
// SumProduct.cpp
//
// This program prompts the user for two integers then
// outputs their sum and product.
//
// ******************************************************

#include <iostream>
using namespace std;

int main()
{
//
// Variable declarations
//
int num1, num2;
int sum, product;


//
// Read in two integers
//
cout << "Enter an integer: ";
cin >> num1;

cout << "Enter another integer: ";


// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
cin >> num2;
sum = num1 + num2;
product = num1 * num2;

cout << "The sum is: " << sum << endl;
cout << "The product is: " << product;

// --------------------------------
// --------- END USER CODE --------
// --------------------------------


cout << "The end!!!\n";

return 0;
}

'Chapter1.1.exe': Loaded 'C:\Users\Nrg\Documents\Visual Studio 2008\Projects\Chapter1.1\Debug\Chapter1.1.exe', Symbols loaded.
'Chapter1.1.exe': Loaded 'C:\Windows\System32\ntdll.dll'
'Chapter1.1.exe': Loaded 'C:\Windows\System32\kernel32.dll'
'Chapter1.1.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcp90d.dll', Symbols loaded.
'Chapter1.1.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll', Symbols loaded.
The program '[1596] Chapter1.1.exe: Native' has exited with code 0 (0x0).
 

Coca Cola

Member
Jul 28, 2007
65
0
0
press ctrl f5 when debugging instead of pressing just f5 or the debug icon in visual studio
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
You either need to run the program outside the IDe or follow the advice of Cogman to place a read request at the end of the program. This allows you to observe the output before the program closes.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Windows sure goes to a lot of trouble to make folks believe its more than a DOS shell...
 
Sep 29, 2004
18,656
68
91
Originally posted by: Cogman
just add cin.get() to the end and it will exit on a key press.

That or toss a sleep in of say, 10 seconds.

Or start from the command prompt, then run your program.