My programme is working just fine but when I press enter after entering the game. It shows the last cout but closes imidiately. What to do?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name = "";
int age = 0;
cout << "Enter your name.\n";
cin >> name;
cout << "Enter your age.\n";
cin >> age;
cout << "You name is:" << name << ".";
cout << "You age is:" << age << ".";
return 0;
}
Run the program from the command line, or change the settings in your IDE to avoid that the window close after the program has terminated.
add getch() just before return 0;
So it will wait for your enter to terminate.
It worked. Thank you so much everyone.