What seems to be the problem in my code?
When I hit Enter after entering my age, the prompt already finishes without asking for my address. I know I can use getline()
for the age, but what if the user enters a non-integer answer?
Sorry, I just started coding yesterday and I want to learn the basics.
#include <iostream>
using namespace std;
int main()
{
int age;
string name, address;
cout << "Please enter the name of the user:" << endl;
getline(cin, name);
cout << "Please enter age of the user:" << endl;
cin >> age;
cout << "Please enter the address of the user:" << endl;
getline(cin, address);
cout << "Your name is " << name << " and you are " << age
<< " years old " << " who lives in " << address << endl;
cout << "Thank you for using my program!";
return 0;
}