- #1
Joe_K
- 33
- 0
Homework Statement
I am writing a program which requires me to make and call a function: string Menu()
This function will display a message to the user. It will then accept the user's choice (as a string) and check it for validity - that is did the user enter a "1", "2", "3", "4", "Q", or "q"? If so, the string should be returned to the calling function (main()). If not, an error message should be displayed and the user should be given another change to make a choice - this should continue until the user enters a valid value.
Homework Equations
The Attempt at a Solution
What I am confused about is how I am supposed to take a string value from the user. Would it be correct to store this string value in a local string variable within the string Menu() function? I don't understand how I am supposed to return the string to the calling function if it is valid.
Right now, I have the function prototyped, and I have the calling statement, I just need to write the actual function code.
Would something like this be correct?
string Menu()
{
while (1)
{
if (user_value==1 || user_value==2 || user_value==3 || user_value==4 || user_value == "q" || user_value == "Q")
return user_value;
break;
else if (user_value!=1 || user_value!=2 || user_value!=3 || user_value!=4 || user_value != "q" || user_value != "Q")
cout<<"invalid choice, try again: "
cin>> userValue;
}}