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
67
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |