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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started