Question: Can you please tell me why the input for cin is not being cleared, and why this is resulting in an infinite loop? Please will
Can you please tell me why the input for cin is not being cleared, and why this is resulting in an infinite loop? Please will rate up!
HERE IS THE CODE:
#include
#include
#include
#include
using namespace std;
int main() {
char userChoice;
cout << "Hello, and welcome to the color space converter program! Which direction would you like to convert?" << endl;
cout << "RGB -> HSV: (Enter 1)" << endl;
cout << "or" << endl;
cout << "HSV -> RGB: (Enter 2)" << endl;
cin >> userChoice;
while (userChoice != '1' || userChoice != '2') {
cin.clear();
cout << "Please enter a valid number: (1 or 2)" << endl;
cin >> userChoice;
}
cout << userChoice;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
