I ran the following code twice.
Once when I input Carlos 22
, the program ran correctly and keep_window_open()
apparently worked as the console
This is caused by invalid input to cin
.
You can add error handling to avoid such issue by following:
change
cin >> first_name >> age;
cout << "Hello, " << first_name << " (age " << age << ")\n";
to
cin >> first_name;
while (!(cin >> age)) {
cout << "Invalid age, please re-enter.\n";
cin.clear();
cin.ignore(std::numeric_limits::max(), '\n');
}