/* Craps Game this is a sample file */ #include #include #include int rollDice( void ); // function prototype int main() { enum Status { CONTINUE, WON, LOST }; int sum, myPoint; Status gameStatus; srand( time( NULL ) ); sum = rollDice(); // first roll of the dice switch ( sum ) { case 7: case 11: // win on first roll gameStatus = WON; break; case 2: case 3: case 12: // lose on first roll gameStatus = LOST; break; default: // remember point gameStatus = CONTINUE; myPoint = sum; cout << "Point is " << myPoint << endl; break; // optional } while ( gameStatus == CONTINUE ) { // keep rolling sum = rollDice(); if ( sum == myPoint ) // win by making point gameStatus = WON; else if ( sum == 7 ) // lose by rolling 7 gameStatus = LOST; } if ( gameStatus == WON ) cout << "Player wins" << endl; else cout << "Player loses" << endl; return 0; } int rollDice( void ) { int die1, die2, workSum; die1 = 1 + rand() % 6; die2 = 1 + rand() % 6; workSum = die1 + die2; cout << "Player rolled " << die1 << " + " << die2 << " = " << workSum << endl; return workSum; }