史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2007-12-07, 05:24 AM   #1
rang0419
註冊會員
榮譽勳章

勳章總數
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設 疑問 - Write a C program that simulates a guessing game.

麻煩請用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
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 09:35 PM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1