#include #include #include using namespace std; // define the new type enum class ResultT {YELLOW_SIGN, TENTACLE, ELDER_SIGN, CTHULHU, EYE, UNKNOWN}; enum struct StatusT:char {ALIVE, INSANE, DEAD, UNKNOWN}; // define some useful constants to use with this type const ResultT FIRST_RESULT = ResultT::YELLOW_SIGN; const size_t RESULT_COUNT = static_cast(ResultT::UNKNOWN) - static_cast(FIRST_RESULT); // define some useful functions ResultT Next(ResultT r); string ResultTToString(ResultT r); ResultT StringToResultT(string s); const int TRIALS = 120; ResultT RollDie(); int main() { ResultT i{ResultT::YELLOW_SIGN}; int j; int yellowCount{0}; int cthulhuCount{0}; for(i = FIRST_RESULT; i < ResultT::UNKNOWN ; i = Next(i)) { cout << ResultTToString(i) << endl; } for(j = 0; j < TRIALS; j++) { i = RollDie(); cout << ResultTToString(i) << endl; switch(i) { case ResultT::YELLOW_SIGN: yellowCount++; break; case ResultT::CTHULHU: cthulhuCount++; break; } } cout << setw(20) << "Yellow Sign" << setw(10) << yellowCount << endl; cout << setw(20) << "Cthulhu" << setw(10) << cthulhuCount << endl; return 0; } ResultT StringToResultT(string s){ ResultT result; if (s == "Yellow Sign") { result = ResultT::YELLOW_SIGN; } else if (s == "Tentacle") { result = ResultT::TENTACLE; } else { result = ResultT::UNKNOWN; } return result; } string ResultTToString(ResultT r){ string result; switch(r){ case ResultT::YELLOW_SIGN: result = "Yellow Sign"; break; case ResultT::TENTACLE: result = "Tentacle"; break; case ResultT::ELDER_SIGN: result = "Elder Sign"; break; case ResultT::CTHULHU: result = "Cthulhu"; break; case ResultT::EYE: result = "Eye"; break; case ResultT::UNKNOWN: default: result ="UNKNOWN"; } return result; } ResultT Next(ResultT r){ ResultT result{ResultT::UNKNOWN}; if (r < ResultT::UNKNOWN) { result = static_cast(static_cast(r) +1 ); } return result; } ResultT RollDie(){ ResultT result{ResultT::UNKNOWN}; int roll; roll = rand() % 12; switch(roll){ case 0: case 1: case 2: case 3: case 4: result = ResultT::YELLOW_SIGN; break; case 5: case 6: case 7: case 8: result = ResultT::TENTACLE; break; case 9: result = ResultT::ELDER_SIGN; break; case 10: result = ResultT::CTHULHU; break; case 11: result = ResultT::EYE; break; } return result; }