![]() |
|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
![]() |
#1 |
註冊會員
|
![]() Write a program to simulate a 6 star lottery game. The rule is as follows:
1.A lottery ticket cost NT $50. 2.The player can pick six numbers from 1 to 42. 3.There is no duplicate lottery number. 4.The prize is shown as follows: Reward Item Rule Prize 6 Stars Price 6 matched numbers 500,000 5 Stars Price 5 matched numbers 10,000 4 Stars Price 4 matched numbers 1,000 3 Stars Price 3 matched numbers 200 1. Display a welcome message to the game. A player enters her or his name. 2. A player can select the number of tickets the player wants to buy and decide if the computer selects the numbers or the player selects the numbers. 3. A player enters the numbers or the computer selects the numbers based on the player's decision. 4. Print the receipt. 5.The player can choose to buy more tickets or not. 6. Show the lottery result. 7. Calculate how much the player spends and wins. 8.The player can choose to continue a new game. 編譯結果如下 ================================================= Welcome to the Happy Lottery Game! Your name: Rita Rita, welcome to the game! ================================================= Enter the number of tickets you want to buy: 2 Computer or Self select (C/S)? S Select numbers: 17 2 6 22 32 42 Select numbers: 10 6 12 7 28 36 ------------------------------------------------- Rita's Receipt: Total pay: 100 Thanks for your playing Happy Lottery! ================================================= Play more (Y/N)? Y ================================================= Enter the number of tickets you want to buy: 1 Computer or Self select (C/P)? P Select numbers: 33 7 18 26 45 36 ------------------------------------------------- Rita's Receipt: Total pay: 50 Thanks for your playing Happy Lottery.. ================================================= Play more (Y/N)? N The lottery result is: 3 7 12 28 38 41 Rita! Congratulations! You won 3 stars. You spent NT $150 and won NT $200. ================================================= Quit the game (Y/N)? N ================================================= Welcome to the lottery game! Your name: Mary Rita, welcome to the game! ================================================= ... ... ================================================= Quit the game (Y/N)? Y ================================================= Thanks for playing! 我不會寫 ![]() ![]() ![]() welcome (char name[]) { printf("===========================================\n"); printf("Welcome to the Happy Lottery Game!\nYour name: "); printf("Your name: "); scanf("%s", name); printf("%s, welcome to the game!\n", name); printf("===========================================\n"); } main() { char name[80]; // string = an array of chars int no_ticket; int lotto[10][3]; // an array for the selected lottery numbers char more; do { welcome(name); printf("Enter the number of tickets you want to buy: "); scanf("%d", &no_ticket); printf("Select 3 numbers: "); scanf("%d%d%d", &lotto[0][0], &lotto[0][1], &lotto[0][2]); printf("You select %d %d %d.\n", lotto[0][0], lotto[0][1], lotto[0][2]); scanf("%c", &more); // read the newline printf("=================================================\n"); printf("Play more (Y/N)? "); scanf("%c", &more); } while (more == 'Y' || more == 'y'); printf("=================================================\n"); printf("Thanks for playing!\n"); } 只寫到以上的其他就不會寫了 |
![]() |
送花文章: 0,
![]() |
|
|
![]() |
||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
如何設定XP的螢幕保護程式的密碼 | yangtao | 軟體應用問題討論區 | 3 | 2003-11-26 06:29 PM |
以手工方式在ASP.NET頁面中實現CodeBehind形式的程式碼編寫 | psac | 程式語言討論區 | 0 | 2003-11-17 12:36 PM |
用Nero燒rm的音樂的外掛程式的問題 | cow1330 | 一般電腦疑難討論區 | 2 | 2003-10-19 09:29 PM |
有人可以幫吾找,兩家驅動程式的公版嗎? | online | 一般電腦疑難討論區 | 0 | 2003-09-19 10:02 PM |