Okay to start off, I am a new to programming, this will more then likely be a simple question to answer. Second thing, a lot of "programmers" I know said "EWW don't start off with C++ its to hard for a beginner." The thing is, I have liked it the most as far as what I have used and it's a relevant language to learn. The reason I make that statement isn't cause I think I am going to be bashed by anyone on this particular forum group for saying that but just in case there are any people just starting out programming like I am: I don't think the language is that scary, and if you want a resource for learning I highly recommend the book this thread is titled with (By: Michael Dawson) - Don't expect to make Halo, its more about learning the basics of programming then it is gaming, but the way he does it gets you thinking about how you would apply what you've learned to programming later once you get better.
Onto my question. Pre-requisite for answer's. Please
DO NOT give me a "better way" to solve the problem, answer the question as posed, I know there are better ways but apparently there is also a method which you can do the program specifically the way he requests else he wouldn't publish a book saying it that way.
The challenge is: Rewrite the Menu Chooser program from the chapter using an enumeration to represent difficulty levels. The variable
choice will still be of type
int.
Menu Chooser Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
// Menu Chooser 1.0
// Demonstrates the switch statement
#include <iostream>
using namespace std;
int main()
{
cout << "Difficulty Levels\n\n";
cout << "1 - Easy\n";
cout << "2 - Normal\n";
cout << "3 - Hard\n\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;
}
|
This is the what I was referencing to get an idea of how to utilize the enumerations when I couldn't figure it out, if it gives you any help trying to figure out where the author was coming from cause part of my issue was i felt the question was vague, I didn't know what all the enumeration was supposed to be affecting, but anyways:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
// Game Stats 3.0
// Demonstrates constants
#include <iostream>
using namespace std;
int main()
{
const int ALIEN_POINTS = 150;
int aliensKilled = 10;
int score = aliensKilled * ALIEN_POINTS;
cout << "score: " << score << endl;
enum difficulty {NOVICE, EASY, NORMAL, HARD, UNBEATABLE};
difficulty myDifficulty = EASY;
enum shipCost {FIGHTER_COST = 25, BOMBER_COST, CRUISER_COST = 50};
shipCost myShipCost = BOMBER_COST;
cout << "\nTo upgrade my ship to a Cruiser will cost "
<< (CRUISER_COST - myShipCost) << " Resource Points.\n";
return 0;
}
|
One last thing is, some of the programmers I know want to use arrays instead of enumerations, like I said before, I want to do things the way it was challenged, so if its between doing it the way that you're more comfortable with (i.e. arrays) instead of doing it with enumeration cause you don't know why anyone would do it that way anyways... I am going to continue in the book whether I get this example or not, help me answer it right, I am going to keep learning either way.