This is my first post and I am sure that I will be having to make a few more.
Anyway after every chapter I am learning I am trying to make my own code so I know I have grasped a certain area. So at the moment I have just finished up on Enumerations.
Here is the code I have made:
#include <iostream>
using namespace std;
int main()
{
enum difficulty {NOVICE, EASY, NORMAL, HARD, SUICIDAL};
int difficultyChoice;
cout << "Please chose a difficulty level (1-5) \nNOVICE(1), EASY(2), NORMAL(3), HARD(4), SUICIDAL(5)" << endl;
cin >> difficultyChoice;
difficulty myDifficulty;
if
(difficultyChoice == 1)
myDifficulty = NOVICE;
if
(difficultyChoice == 2)
myDifficulty = EASY;
if
(difficultyChoice == 3)
myDifficulty = NORMAL;
if
(difficultyChoice == 4)
myDifficulty = HARD;
if
(difficultyChoice == 5)
myDifficulty = SUICIDAL;
cout << "\nPress the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
Now I know that each constant (NOVICE, EASY etc.) is given a value and in this case it is 0,1,2,3 and 4. So when the user chooses a difficulty level it is displaying the numeric value.
What I was wondering was is there a way to have it display the text value of NOVICE, EASY etc, or is it just written this way to make it easier for us to remember the value by name instead of number, and not actually possible to output the text value this way?
Im sure with further reading and teaching I will find a better way to do this but its only my 3rd day.
Its more coding but still setting the value as required.
Again Im glad for the responses and Im sure I will be needing some more insight in the future since Im teaching myself so dont have any one else to ask :)