However, the solution given has brought up a question.
I just can't figure out the connection between "choice" and "level", how does the value of choice get assigned to level so the program knows which you've chosen?
Is it because that "switch" is automatically assigned to the previous enumeration?
We're saying to start the numeration at 1, thus easy == 1, normal == 2, hard == 3.
Within the switch, "case easy:" is the same as saying "case 1:".
Choice is user input, so only if the user inputs 1 or 2 or 3 will will be checked against case easy, normal, hard. All other input will be caught by the default statement.
Unfortunately "very small classes" doesn't mean much to me, just started this a week ago.
I know I've read the definition but I don't learn stuff until I do it.
Although I do have one more question about the switch and enum relationship.
Since within the switch, at each case line, you use a specific enumerator(tion?), (east, normal, hard), then it is possible to enumerate and then to do so again but can't use the same words (easy, normal, hard).
I just want to understand if upon enumerating, does the nesxt switch have refer to the previous enumeration or can I have multiple enumerations and then is the switches for them in any order I wish?
enum fruit_t { not_a_fruit, apple, banana, cherry };
fruit_t fruit;
cout << "What is your favorite fruit:\n"" a - apple\n"" b - banana\n"" c - cherry\n""> "
<< flush;
char ch;
cin >> ch;
switch (toupper( ch ))
{
case'A': fruit = apple; break;
case'B': fruit = banana; break;
case'C': fruit = cherry; break;
default: fruit = not_a_fruit;
}
if (fruit == not_a_fruit)
cout << "Hey, that's not a fruit!\n";
else
cout << "I like that too!\n";
What this does is keep the proper stuff together, and the improper stuff separate.
Lines 11..20 deal with converting the user's input into a fruit_t.
Lines 22..n don't care what the user's input looks like. All it cares about is the fruit.