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.
Comments
Post a Comment