Good afternoon everyone,
I was reading the "Jumping into c++" book when I got to exercise 4-1 that states:
"Ask the user for two users' ages, and indicate who is older; behave differently if both are over 100"
So I wrote my code (but I'm only stating what matters)
So here is my problem:Code:string name1; string name2; int age1; int age2; cout << "User 1 please state your name: " << endl; getline( cin, name1, '\n' ); cout << "User 1 please tell us your age: " << endl; cin >> age1; cout << "User 2 please state your name: " << endl; getline( cin, name2, '\n' ); cout << "User 2 please tell us your age: " << endl; cin >> age2;
Immediately after the "User 2 please state your name: " is printed on the screen, "User 2 please tell us your age: " is printed, making it so I can't type the User 2' name, this happens using the "getline( cin, name2, '\n' )" (underlined), but when I use a "cin >> name2", the program works just fine.
What am I doing wrong? Can someone help?
Thanks,
Rodrigo



2Likes
LinkBack URL
About LinkBacks



So you don't get that doubt for your User 1 input?