C++ Simple input/out program + enumerators
Assignment"Rewrite the menu chooser program from chapter using an
enumerator to represent difficulty levels. the variable choice will still
be of type int."
The first set of code is the original menu chooser program in its original
untainted form. The second set of code is what I added to it in order to
complete the assignment.
The only thing I want to ask is: Did I complete my assignment correctly.
If I did it wrong, can someone please explain what I did wrong. I'm very
new at this.
Code Set # 1 - Original
#include <iostream>
using namespace std;
int main()
cout << "Difficulty Levels\n\n";
cout << "1 - Easy\n";
cout << "2 - Normal\n";
cout << "3 - Hard\n";
int choice;
cout << "Choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "You picked Easy.\n";
break;
case 2:
cout << "You picked Normal.\n";
break;
case 3:
cout << "You picked Hard.\n";
break;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}
Code Set # 2 - Assignment
#include <iostream>
using namespace std;
int main()
{
cout << "Difficulty Levels\n\n";
cout << "0 - Novice\n";
cout << "1 - Easy\n";
cout << "2 - Normal\n";
cout << "3 - Hard\n";
cout << "4 - Unbeatable\n\n";
enum {Novice = 0, Easy = 1, Normal = 2, Hard = 3, Unbeatable = 4};
int choice;
cout << "Choice: ";
cin >> choice;
switch (choice)
{
case 0:
cout << "You have picked Novice.\n";
break;
case 1:
cout << "You picked Easy.\n";
break;
case 2:
cout << "You picked Normal.\n";
break;
case 3:
cout << "You picked Hard.\n";
break;
case 4:
cout << "You picked Unbeatable.\n";
break;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}
No comments:
Post a Comment