my program disappears

im trying to teach my self c++ from a book and it has several activities.
i compile it fine but when i run it, it runs disappears and stays running.

#include <iostream>

int add(int x, int y)
{
return (x+y);
}

int main()
{
typedef unsigned short US;
typedef const unsigned short CUS;
US score = 0;
CUS TOUCH = 6;
CUS FELD = 3;
CUS EXTRA = 1;
CUS SAFETY = 2;

std::cout << "our team scores a touchdown!\n";
std::cout << "we now have" << add(TOUCH, score) << "points!\n";
std::cout << "our team scores a feald goal!\n";
std::cout << "we now have" << add(FELD, score) << "points!\n";
std::cout << "our team scores an extra point!\n";
std::cout << "we now have" << add(EXTRA, score) << "points!\n";
std::cout << "our team scores a safety point\n";
std::cout << "we now have" << add(SAFETY, score) << "points!\n";
std::cout << "THE GAME IS NOW OVER! WE HAVE" << score << "points!\n";
return 0;
}
You have not told it to stay open, or hold the window from closing.

People on this board are sensitive to system("PAUSE"); so a better solution would be
getchar();

You'll want to place this before the return 0; statement at the end, and after the last line of you game code.
Read here http://www.cplusplus.com/forum/beginner/1988/
People are against system("pause") if it is included in the actual code. If getch() cannot work, you can write a simple batch file and put it into your executable directory. Namely, I don't think this is trouble:

1
2
CALL myapplication.exe
PAUSE
Last edited on
Try this:
cin.get();

place that code just before return 0;

Also if you are ever going to use system("pause"); use system("pause>nul"); insted you can test the difference for yourself
This article was written for your problem:
http://www.cplusplus.com/articles/iw6AC542/
Topic archived. No new replies allowed.