![]() |
Write a C program that simulates a guessing game.
麻煩請用C 可以的話幫我加註解一下ˊˋ"
好難阿......:on_22: Write a C program that simulates a guessing game. (1)Each time you choose among 6 possible guesses. The correct guess is based on the following game board which divides the numbers into rows and columns as shown below: Left---Center---Right 1--------2--------3 4--------5--------6 7--------8--------9 10------11-------12 The following table shows your choice and risk-winning rate: Choice-----------Risk:Winning Odd|Even-------------1:1 Left|Center|Right------1:2 Number---------------1:12 For example, you guess a low number and your points at risk are 20. If you guess right, you'll get 20 points. (2)The program will generate a random number between 1 and 12. (3)Each correct guess will be rewarded with points based on how many of your current points you risked. (4)The player can choose to continue to play. (5)If the player quit the game, print the winning or loosing points of the player. Hint: Refer to the folloing code: main() { char option, go; do { printf("=======================================================\n"); printf("Guesses Choice:\n"); printf("O-Odd E-Even F-Left C-Center R-Right N-Number\n"); printf("=======================================================\n"); printf("Enter your choice: "); scanf("%c", &option); getchar(); // get the carriage return "\n" switch (option) { case 'O': case 'o': printf("Odd number\n"); break; case 'E': case 'e': printf("Even number\n"); break; case 'F': case 'f': printf("Left number\n"); break; case 'C': case 'c': printf("Central number\n"); break; case 'R': case 'r': printf("Right number\n"); break; case 'N': case 'n': printf("A number\n"); break; default: printf("Try again!\n"); } printf("Continue (Y/N)? "); scanf("%c", &go); getchar(); // get the carriage return "\n" } while (go == 'Y' || go == 'y'); } A possible run could look like as follows: ========================================================== Guesses Choices: O-Odd E-Even F-Left C-Center R-Right N-Number ========================================================== Enter your choice: O Point at risk: 20 The winning number is 12. You lost 20 points. Continue (Y/N)? Y ========================================================== Guesses Choices: O-Odd E-Even L-Left C-Center R-Right N-Number ========================================================== Enter your choice: C Point at risk: 10 The winning number is 5. You won 30 points. Continue (Y/N)? Y ========================================================== Enter your choice: N Enter your number: 7 Point at risk: 10 The winning number is 10. You lost 10 points. Continue (Y/N)? N ========================================================== Total number of guesses: 3 Your current point: 0 |
所有時間均為台北時間。現在的時間是 11:47 AM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *