Still having a little trouble

My program is shutting down earlier than I want it to. I have tried using all of the pause options given to me and still having trouble. Here is the code as it was originally written. I have added comments in it where I am having the problem. I hope this will help to understand my problem better.

#include <iostream>

using namespace std;

int main()
{
int score;
cout << "Enter your score:";
cin >> score;

/* Here is where the problem occurs. It will let me enter the score, but as soon as I hit the Enter key it flashes through the rest and closes the program. I have tried every suggestion given to me so far and nothing is keeping open. It is so frustrating! */

if (score > 500)
cout << "\nYou got over 500. Nice score\n.";
else
cout <<"\nYou got 500 or less. Nothing to brag about.\n";


return 0;
}
Include this line at end of your code (before 'return 0'):

getchar();

for a 'press any key to continue' state.

For further information http://www.cplusplus.com/reference/clibrary/cstdio/getchar.html, ok?
or if you run on windows use system("pause") as the getchar(); can be taken up from a cin or something else
Hey man,

Try Sleep(...) within the windows.h header file. every 1000 equals 1 second.
Sleep(3000) = 3 seconds. Try this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <windows.h>
using namespace std;

int main() 
{
long score;
cout << "Enter your score: ";
cin >> score;
if (score > 500) { cout << "\nYou got over 500. Nice score.\n"; }
else {
cout << "\n You got 500 or less. Nothing to brag about\n"; }
Sleep(6000); //let the program wait 6 secs before it closes
return 0;
}


I hope it will help ya ^^
Thanks for all the good info it all helped me.
Thanks for all the good info it all helped me.
Topic archived. No new replies allowed.