Write a program that allows the user and computer to alternately select numbers from 3 to 12. The numbers are totaled after each entry. A winner is declared when the total is greater than 100. The last one to enter a number is the winner. Have the computer ask whether the user wishes to go first or second. The computer should disallow cheating. Special Instructions: When solving a more complex problem such as this one it is a good idea to have a plan of attack. You must first break the large problem down into smaller parts. Begin the coding by working on each small part until it works correctly. Add more parts until the complete problem is solved. This problem should be broken down into these parts: - Code for a simplified version of the game.
- Write the game code for a basic version of the game that does not include taking turns or playing again. Have the player enter a value and then have the computer take a turn. Use a while loop so the game continues until the total value exceeds 100.
- Code to prevent cheating.
- Add a while loop around the code that allows the player to enter a value. The loop should be written so that the game only accepts values from 3 to 12 too be used.
- Code for starting first or second.
- Before the code of the game write code that asks the user whether he/she would like to go first or second. Place a while loop around the code so that only the values 1 or 2 are accepted as valid entries.
- Change the code of the game so that it can alternate turns. You will need to use If to separate the user's turn from the computer's.
|