![]() |
|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
![]() ![]() |
|
主題工具 | 顯示模式 |
![]() |
#1 |
註冊會員
|
![]() 麻煩請用C 可以的話幫我加註解一下ˊˋ"
好難阿...... ![]() 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 |
![]() |
送花文章: 5,
![]() |