本帖最後由 tonyh 於 2012-2-11 17:34 編輯
我們將開發一個三個欄位的吃角子老虎機遊戲程式,
其中獎規則如下:
任一欄出現7 --> 獎金變兩倍
任兩欄出現7 --> 獎金變十倍
三欄都出現7 --> 獎金變一百倍
本次評估方式說明:
測試看看大約要跑幾次才能拉中第一特獎777- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a, b, c;
- int run=0;
- cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
- cout<<"中獎規則說明:"<<endl;
- cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;
- cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;
- cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;
- cout<<"本次測試方式: 測試看看大約要跑幾次才能拉中第一特獎777"<<endl;
- system("pause");
- srand(time(NULL));
- while(true)
- {
- run++;
- a=rand()%10;
- b=rand()%10;
- c=rand()%10;
- cout<<a<<" "<<b<<" "<<c<<endl;
- if(a==7 && b==7 && c==7)
- {
- break;
- }
- }
- cout<<"共計"<<run<<"次!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |