Hello, I have a quick snipet of code I'm writing currently:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cout << "What is your first number?" << endl;
cin >> fNum;
cout << "What is your second number?" << endl;
cin >> sNum;
while (fNum >= sNum) { //Check user input
cin.ignore(256, '\n');
cin.clear();
cout << "Invalid input, first number must be less than second" << endl;
cout << "What is your first number?" << endl;
cin >> fNum;
cout << "What is your second number?" << endl;
cin >> sNum;
cout << sNum;
}
What I'm trying to do here is make it so that if when prompted for a user's first number and they were to enter in 20 10 then I would want to clear the white space, and then the 10. As of now if I enter in 20 10 it will store 20 for fNum and then 10 for sNum. I was looking at regex, but that doesn't seem to fit what I'm attempting to do. Any ideas? I've been stumped on this for a day or so playing around with cin.clear() and what not.