![]() |
|
|||||||
| 論壇說明 |
|
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
|
主題工具 | 顯示模式 |
|
|
#2 (permalink) |
|
註冊會員
|
我是用Virtual C 寫的...
換平台有些寫法可能要自己改一下哦! 看不懂再問吧!! 有點複雜的說加上貼上來後格式會全跑掉... ><" 我在想想看可不可以弄成Class或方法嗎.... 有想到再給你看看摟! 其他人有寫出來可以借我看看嗎? 我想多學幾種方法... 感謝喔!! 可執行檔放在 http://www.filedropper.com/test2_1 你可以先試試看再去看程式碼!!! 比較好懂! 我是先用固定的開獎號碼做喔!! 要改自動產生開獎號碼把註解地方(/* */)拿掉就可以了! #include "stdafx.h" #include "stdlib.h" #include "stdio.h" #include "time.h" using namespace System; int main(array<System::String ^> ^args) { int i, j, k, tickets, pay=0, total, totalpay, select[6]={3,7,12,28,38,41}, **Computerselect=new int *[tickets], stars, Maxstars; //tickets是購票數量,pay每次購買票數金額,totalpay總共要付多少錢,total中獎金額,select開獎號碼,Computerselect玩家購買票號(用二維動態陣列存),stars每組中幾個號碼,Maxstars最多中幾個號碼 char name[128], choice; //name玩家名字,choice選擇用(有重覆使用!) do{ Maxstars=0; //因為可能有多位玩家! 所以每次開始時要清空前筆資料! stars=0; totalpay=0; total=0; printf("=================================================\n"); printf("Welcome to the Happy Lottery Game!\nYour name:"); scanf("%s",name); printf("%s, welcome to the game!\n",name); srand((unsigned)time(NULL)); //產生亂數用! 網路上都查的到! /* for(i=0; i<6; i++) //自動選則開獎號碼(隨機產生的開獎號碼) { d: select[i]=rand()%37; for(j=0; j<i; j++) //檢查選號是否重覆 { if(select[i]==select[j] || select[i]==0) //檢查選號是否重覆或產生0的亂數 goto d; } } */ do{ //進入遊戲 printf("=================================================\nEnter the number of tickets you want to buy:"); scanf("%d",&tickets); for(i=0; i<tickets; i++) { Computerselect[i] = new int[6]; } c: printf("Computer or Self select (C/S)?"); scanf(" %c",&choice); //%c前一定要空一格才會等待輸入!! 為什麼~因為經驗!!! 不空格會直接往下直行喔!!! switch(choice) { case 'C': case 'c': stars=0; for(i=0; i<tickets; i++) //機器自動選號 { printf("Select numbers:"); for(j=0; j<6; j++) //機器自動選號 { a: Computerselect[i][j]=rand()%37; for(k=0; k<j; k++) //檢查選號是否重覆 { if(Computerselect[i][j]==Computerselect[i][k] || Computerselect[i][j]==0) //檢查選號是否重覆或產生0的亂數 goto a; //a為標籤! 會跳到 a: 的地方開始執行 } printf(" %d",Computerselect[i][j]); } printf("\n"); } for(i=0; i<tickets; i++) //判斷中幾顆星 { for(j=0; j<6; j++) { for(k=0; k<6; k++) { if(Computerselect[i][j]==select[k]) //判斷數字是否重複(中獎) { stars++; } } } } if(Maxstars<stars) //將最多的中獎數量存起來 Maxstars=stars; printf("-------------------------------------------------\n"); break; case 'S': case 's': stars=0; for(i=0; i<tickets; i++) //自行選號 { printf("Select numbers:"); b: scanf("%d %d %d %d %d %d",&Computerselect[i][0], &Computerselect[i][1], &Computerselect[i][2], &Computerselect[i][3], &Computerselect[i][4], &Computerselect[i][5]); for(j=0; j<6; j++) { if(Computerselect[i][j]<1 || Computerselect[i][j]>42) //判斷數字是否超出範圍 { printf("數字超出範圍! 請重新輸入!\n"); goto b; } for(k=0; k<j; k++) //檢查選號是否重覆 { if(Computerselect[i][j]==Computerselect[i][k]) //判斷數字是否重覆 { printf("數字重覆! 請重新輸入!\n"); goto b; } } } } for(i=0; i<tickets; i++) //判斷中幾顆星 { for(j=0; j<6; j++) { for(k=0; k<6; k++) { if(Computerselect[i][j]==select[k]) //判斷數字是否重複(中獎) { stars++; } } } } if(Maxstars<stars) //將最多的中獎數量存起來 Maxstars=stars; printf("-------------------------------------------------\n"); break; default: printf("代碼錯誤!! 請重新輸入!\n"); goto c; } //結束switch pay=tickets*50; totalpay+=pay; printf("%s's Receipt:\nTotal pay: %d\nThanks for your playing Happy Lottery!\n",name, pay); printf("=================================================\nPlay more (Y/N)?"); scanf(" %c",&choice); }while(choice=='Y' || choice=='y'); printf("The lottery result is:\n"); for(i=0; i<6; i++) //印出開獎號碼 { printf(" %d",select[i]); } printf("\n"); if(Maxstars>2) //判斷中獎金額 total=200; else if(Maxstars>2) total=200; else if(Maxstars>3) total=1000; else if(Maxstars>4) total=10000; else if(Maxstars>5) total=500,000; printf("%s! Congratulations! You won %d stars.\nYou spent NT $%d and won NT $%d.\n=================================================\nQuit the game (Y/N)?",name, Maxstars, totalpay, total); scanf(" %c",&choice); }while(choice=='N' || choice=='n'); printf("Thanks for playing!\n"); system("pause"); return 0; } 此帖於 2009-09-01 05:45 PM 被 ~愛搞笑的好人~ 編輯. 原因: 增加內容 |
|
|
送花文章: 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 |