- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a, b, c;
- int run=1;
- float one=0, two=0, three=0;
- float rate[3];
- int tast;
- cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
- cout<<"中獎規則說明:"<<endl;
- cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;
- cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;
- cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;
- cout<<"本次測試方式: 讓使用者自行輸入欲測試的次數, 並以百分比的方式分別表示出中第一特獎, 二獎與三獎的機率."<<endl;
- cout<<"使用者請輸入您想要預測的次數: ";
- cin>>tast;
- srand(time(NULL));
- while(run<=tast)
- {
- a=rand()%10;
- b=rand()%10;
- c=rand()%10;
- cout<<a<<" "<<b<<" "<<c<<endl;
- if(a==7 && b==7 && c==7)
- {
- one++;
- }
- if((a==7 && b==7 && c!=7)||(a!=7 && b==7 && c==7)||(a==7 && b!=7 && c==7))
- {
- two++;
- }
- if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
- {
- three++;
- }
- run++;
- }
- cout<<"在這"<<tast<<"次的測試中, 三獎中了"<<three<<"次, 二獎中了"<<two<<"次, 第一特獎中了"
- <<one<<"次"<<endl;
- rate[0]=three/tast*100;
- rate[1]=two/tast*100;
- rate[2]=one/tast*100;
- cout<<"中三獎(任一欄出現7)的機率是: "<<rate[0]<<"%"<<endl;
- cout<<"中二獎(任兩出現7)的機率是: "<<rate[1]<<"%"<<endl;
- cout<<"中第一特獎(三欄都出現7)的機率是: "<<rate[2]<<"%"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |