- #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 d;
- cout<<"$$ 吃角子老虎機中獎機率評估程式 $$"<<endl;
- cout<<"中獎規則說明:"<<endl;
- cout<<"任一欄出現 7-->您投下的賭注成兩倍"<<endl;
- cout<<"任兩欄出現 7-->您投下的賭注成十"<<endl;
- cout<<"三欄現 7-->您投下的賭注成一百"<<endl;
- cout<<"測試方式:讓使用者自行輸入欲測試的次數, 並以百分比的方式分別表示出中第一特獎, 二獎與三獎的機率"<<endl;
- cout<<"請輸入您要測試的次數"<<endl;
- cin>>d;
- system("pause");
- srand(time(NULL));
- while(run<=d)
- {
- 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++;
- }
- rate[0]=three/d*100;
- rate[1]=two/d*100;
- rate[2]=one/d*100;
- cout<<"在這"<<d<<"次測試中共中三獎"<<three<<"次,中獎機率"<<rate[0]<<"%"<<endl;
- cout<<"在這"<<d<<"次測試中共中二獎"<<two<<"次,中獎機率"<<rate[1]<<"%"<<endl;
- cout<<"在這"<<d<<"次測試中共中特獎"<<one<<"次,中獎機率"<<rate[2]<<"%"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |