返回列表 發帖
  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 tast;
  12.    cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
  13.    cout<<"中獎規則說明:"<<endl;
  14.    cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;
  15.    cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;
  16.    cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;
  17.    cout<<"本次測試方式: 讓使用者自行輸入欲測試的次數, 並以百分比的方式分別表示出中第一特獎, 二獎與三獎的機率."<<endl;
  18.    cout<<"使用者請輸入您想要預測的次數: ";
  19.    cin>>tast;
  20.    srand(time(NULL));
  21.    while(run<=tast)
  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)
  28.        {
  29.             one++;
  30.        }
  31.        if((a==7 && b==7 && c!=7)||(a!=7 && b==7 && c==7)||(a==7 && b!=7 && c==7))
  32.        {
  33.             two++;
  34.        }
  35.        if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
  36.        {
  37.             three++;
  38.        }
  39.        run++;
  40.    }

  41.    cout<<"在這"<<tast<<"次的測試中, 三獎中了"<<three<<"次, 二獎中了"<<two<<"次, 第一特獎中了"
  42.    <<one<<"次"<<endl;
  43.    rate[0]=three/tast*100;
  44.    rate[1]=two/tast*100;
  45.    rate[2]=one/tast*100;
  46.    cout<<"中三獎(任一欄出現7)的機率是: "<<rate[0]<<"%"<<endl;
  47.    cout<<"中二獎(任兩出現7)的機率是: "<<rate[1]<<"%"<<endl;
  48.    cout<<"中第一特獎(三欄都出現7)的機率是: "<<rate[2]<<"%"<<endl;  
  49.    system("pause");
  50.    return 0;
  51. }
複製代碼

TOP

返回列表