I have a homework assignment that deals with creating a command line menu, and then selecting items from that menu that do something. the items need to be selected by using either a lowercase or uppercase letter that represents that specific menu item. for example, if i want to print a sentence, then i need to type either lowercase 'p' or uppercase 'P'. right now i dont want help getting each menu item to work, but i need help with configuring my program so that when i type p or P, it will do that function, or if i select e or E, it will perform that function...etc. this is the code I have right now, I was wondering if someone could tell me if I am on the right track. right now i was thinking of declaring each valid character for input as a character, and then inputing that character. i then made a simple if/else statement to test if it works. thanks for any help you can give me.
#include
using std::cout; using std::cin; using std::endl;
int main() { char x [1]; char c [1]; char C [1]; char p [1]; char P [1]; char e [1]; char E [1]; char d [1]; char D [1]; char q [1]; char Q [1];
cout << "You can perform the following tasks: \n"; cout << "(p) Print a Sentence \n"; cout << "(c) Capitalize the Sentence \n"; cout << "(e) Encode the Sentence \n"; cout << "(d) Decode the Sentence \n"; cout << "(q) Quit \n"; cout << "Please Select one... \n";
cin.getline (x, 1);
if (x = c || x = C) //if you type either lowercase c or uppercase C, test was successful cout << "Test Successful /n";
else { cout << "Test Failed /n"; }
return 0; }
Yes it looks ok apart from a few syntax errors.