Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

Students also viewed these Databases questions