Question
I am working on a assignment on C++ that deals with Boolean function, and I am having trouble figuring it out. The question is..
I am working on a assignment on C++ that deals with Boolean function, and I am having trouble figuring it out. The question is..
"The menu asks the user to enter an option. The user should be able to enter any string for the option. The first character of the string entered is upper-cased and used as the option. Examples: Enter an option: o converted to O and accepted Enter an option: only first character o is capitalized to O and accepted When an invalid option is entered, the program prints Invalid option, enter I, O, L or X! and repeats the input until a valid option Is entered. If it finds the given character, it returns true. If it does not find the character, it returns false. This can be used instead of a long list of conditional expressions. Ex: so we do NOT have to write: if (c !=X && c!=O && c!=L && for ever & ever && c !=Z) instead of if (!isValidOption(c,XOLZ))"
Basically it asks user to type in character X, O , L, or I. But if the user type in lowercase of those letters it will also accept the input and if they type a word (string) that starts with one of those letters it will also accept the input.
Our professor gave us a hint by providing-
string userInput;
char option;
cout
if (cin.peek() == ' ') cin.ignore();
getline(cin, userInput);
option = toupper(userInput[0]);
Example output is below.
What I have so far is below and I am kind of stuck on what to do next..
bool isValidOption(char option, string & valOptions) {
return true;
return false;
}
I - List our Inventory 0-Make an Order L - List al1 Orders made X - Exit Enter an option: what option? Inualid option enter I 0. L or X! Enter an option: try again? Invalid option. enter I. 0. L or ! Enter an option: ok this will worlkStep 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