Do While loop on C++
I need to program a do while loop in which the user have to choose between option A,a, B,b or C,c. I need a do while loop that if other letter (different from options is choose) the loop print a cout saying "Invalid selection. Plese, enter the selection again.
I have one, but isn't working well
int main()
{
char option;
do
{
cout<<"Please choose one of the following options: "<<endl<<endl;
cout<<"Option A - Julian Calendar"<<endl;
cout<<"Option B - Powerlifting"<<endl;
cout<<"Option C - GPA"<<endl<<endl;
cout<<Option :";
cin>>option;
} while (option !='A' || option !='a' || option !='B' || option !='b' || option !='C' || option !='c')
return 0;
}
#include <iostream> using namespace std; int main() { char option; bool is_option_invalid; do { cout << "Please choose one of the following options: " << endl << endl; cout << "Option A - Julian Calendar" << endl; cout << "Option B - Powerlifting" << endl; cout << "Option C - GPA" << endl << endl; cout << "Option :"; cin >> option; is_option_invalid = option != 'A' && option != 'a' && option != 'B' && option != 'b' && option != 'C' && option != 'c'; if (is_option_invalid) { cout << "Invalid selection. Please, enter the selection again." << endl << endl; } } while (is_option_invalid); return 0; }
Get Answers For Free
Most questions answered within 1 hours.