返回列表 發帖
  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 one=0, two=0, three=0;
  10.     float rate[3];
  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.     cout<<"請輸入您要測試的次數"<<endl;
  19.     cin>>d;
  20.     system("pause");
  21.     srand(time(NULL));
  22.     while(run<=d)
  23.     {
  24.                a=rand()%10;
  25.                b=rand()%10;
  26.                c=rand()%10;
  27.                cout<<a<<" "<<b<<" "<<c<<endl;
  28.                if(a==7 && b==7 && c==7)
  29.                {
  30.                            one++;
  31.                }
  32.                if((a==7 && b==7 && c!=7)||(a!=7 && b==7 && c==7)||(a==7 && b!=7 && c==7))
  33.                {
  34.                            two++;
  35.                }
  36.                if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
  37.                {
  38.                            three++;
  39.                }
  40.                
  41.                
  42.         run++;   
  43.     }
  44.     rate[0]=three/d*100;
  45.     rate[1]=two/d*100;
  46.     rate[2]=one/d*100;
  47.     cout<<"在這"<<d<<"次測試中共中三獎"<<three<<"次,中獎機率"<<rate[0]<<"%"<<endl;
  48.     cout<<"在這"<<d<<"次測試中共中二獎"<<two<<"次,中獎機率"<<rate[1]<<"%"<<endl;   
  49.     cout<<"在這"<<d<<"次測試中共中特獎"<<one<<"次,中獎機率"<<rate[2]<<"%"<<endl;
  50.     system("pause");
  51.     return 0;   
  52. }
複製代碼

TOP

返回列表