c++ - Cin won't let user enter anything in console before moving on -


i'm trying let user enter race times (in minutes) @ each checkpoint. when try run in console, skips on input user except name.

#include <iostream> #include <cmath> #include <string>  using namespace std;   int main(void)  {    int racername;   int checkpointone;   int checkpointtwo;   int checkpointthree;   int checkpointfour;    cout << "enter racer's first name: ";   cin >> racername;    cout << "enter time (in minutes) @ checkpoint 1: ";   cin >> checkpointone;   cout << "\nenter time (in minutes) @ checkpoint 2: ";   cin >> checkpointtwo;   cout << "\nenter time (in minutes) @ checkpoint 3: ";   cin >> checkpointthree;   cout << "\nenter time (in minutes) @ checkpoint 4: ";   cin >> checkpointfour;    return 0; } 

racername should string, not int.

string racername; 

when type non-integer in response prompt, conversion fails. same thing happens other cin lines, because it's leaving name typed in input buffer, , each of them trying convert number.

demo


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -