// Program file: dice.cpp // This program demonstrates enumerated data and the switch statement #include #include #include using namespace std; int rolldice(); int main() { enum Status {CONTINUE, WON, LOST}; int sum, mypoint; Status gamestatus; system("cls"); srand(time(0)); sum = rolldice(); switch (sum) { case 7: case 11: gamestatus = WON; break; case 2: case 3: case 12: gamestatus = LOST; break; default: gamestatus = CONTINUE; mypoint = sum; cout << "Point is " << mypoint << endl; } while (gamestatus == CONTINUE) { sum = rolldice(); if (sum == mypoint) gamestatus = WON; else if (sum == 7) gamestatus = LOST; } if (gamestatus == WON) cout << "Player wins" << endl; else cout << "Player loses" << endl; cout << "gamestatus is " << gamestatus << endl; system("pause"); return 0; } int rolldice() { int die1, die2, total; die1 = 1 + rand() % 6; die2 = 1 + rand() % 6; total = die1 + die2; cout << "Player rolled " << die1 << " + " << die2 << " = " << total << endl; return total; }