返回列表 發帖
  1. #include<iostream>   
  2. #include<cstdlib>   
  3. #include<ctime>      
  4. using namespace std;
  5. int main()
  6. {
  7.     int a,b,c;
  8.     int run=1;
  9.     float three=0;
  10.     int rate;
  11.     int d;
  12.     cout<<"$$ 吃角子老虎機中獎機率評估程式 $$"<<endl;
  13.     cout<<"中獎規則說明:"<<endl;
  14.     cout<<"任一欄出現 7-->您投下的賭注成兩倍"<<endl;
  15.     cout<<"任兩欄出現 7-->您投下的賭注成十"<<endl;
  16.     cout<<"三欄現 7-->您投下的賭注成一百"<<endl;
  17.     cout<<"請輸入您要測試的次數"<<endl;
  18.     cin>>d;
  19.     system("pause");
  20.     srand(time(NULL));
  21.     while(run<=d)
  22.     {
  23.                a=rand()%10;
  24.                b=rand()%10;
  25.                c=rand()%10;
  26.                cout<<a<<" "<<b<<" "<<c<<endl;
  27.                if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
  28.                {
  29.                            three++;
  30.                }
  31.         run++;   
  32.     }
  33.     rate=three/d*100;         
  34.     cout<<"在這"<<d<<"次測試中共中三獎"<<three<<"次,中獎率是" <<rate<<"%";   
  35.   
  36.     system("pause");
  37.     return 0;   
  38. }
複製代碼

TOP

返回列表