/************************************************************************ *Triskaidekaphobia *Dsimulates the game thirteen stones *programmer: Jason Calcagno *AP/IB computer science *Input: number of stones selected on a fiven turn *Output: a message declaring the winner ***********************************************************************/ #include #include void main() { int numStones, // Number of stones left numPicked, // Number of stones picked up by current player player; // Player identifier (1 or 2) // Output the rules. cout << endl; cout << "You have before you a pile of 13 stones. " << "Players 1 and 2 alternate" << endl; cout << "picking from 1 to 3 stones off the pile. " << "The last player to pick up " << endl; cout << "a stone is the winner. Good luck." << endl; cout << endl; // Play the game. numStones = 13; player = 1; while (numStones>=1) // While there is a stone remaining { cout << "Player " <> numPicked; if ((numPicked > 3)||(numPicked<1)) { cout<< "sorry, thats not legal... pick again... "; cin >> numPicked; } if (numPicked>numStones) { cout<< "sorry, thats not legal... pick again... "; cin >> numPicked; } if ((numPicked>=1)&&(numPicked <= 3)) { numStones = numStones - numPicked; } if (numStones > 0) { if (player == 1) { player = 2; } else { player = 1; } } } cout << "No stones left -- " << "player " << player << " is the winner!" << endl; } /* You have before you a pile of 13 stones. Players 1 and 2 alternate picking from 1 to 3 stones off the pile. The last player to pick up a stone is the winner. Good luck. Player 1 pick your stones. you have 13 to pick from : 3 Player 2 pick your stones. you have 10 to pick from : 1 Player 1 pick your stones. you have 9 to pick from : 2 Player 2 pick your stones. you have 7 to pick from : 2 Player 1 pick your stones. you have 5 to pick from : 1 Player 2 pick your stones. you have 4 to pick from : 3 Player 1 pick your stones. you have 1 to pick from : 1 No stones left -- player 1 is the winner! Press any key to continue You have before you a pile of 13 stones. Players 1 and 2 alternate picking from 1 to 3 stones off the pile. The last player to pick up a stone is the winner. Good luck. Player 1 pick your stones. you have 13 to pick from : 1 Player 2 pick your stones. you have 12 to pick from : 3 Player 1 pick your stones. you have 9 to pick from : 2 Player 2 pick your stones. you have 7 to pick from : 4 sorry, thats not legal... pick again... 1 Player 1 pick your stones. you have 6 to pick from : 3 Player 2 pick your stones. you have 3 to pick from : 3 No stones left -- player 2 is the winner! Press any key to continue */