Problem with adding numbers
Hey, I'm trying to write a very simple program to add up numbers, but after I enter the second number the program finishes. Here is the code:
#include <iostream>
using namespace std;
int main()
{
int num1, num2, total;
cout <<"Enter the first number: ";
cin >> num1;
cout <<"Enter the second number :";
cin >> num2;
total = num1 + num2;
cout <<"The total is :" << total << endl;
cin.get();
return 0;
}
it seems to ignore the cin.get function. Can anyone help please? I'm using Dev-C++ 5 beta. Thanks in advance.
-Pinny.
[706 byte] By [
Pinny] at [2007-11-11 7:34:54]

# 1 Re: Problem with adding numbers
we've had several posts about this very issue recently. You can scroll down the thread list and find a more detailed answer, but the bottom line is that you need to add a certain input statement that causes the program to wait until the user presses a key. Something like
char c;
cin>>c; before the last line in main() would do the trick.
Danny at 2007-11-11 21:02:03 >
