返回列表 發帖
  1. #include <iostream>

  2. #include <cstdlib>

  3. #include <ctime>

  4. using namespace std;

  5. int main()

  6. {

  7.    int a, b, c,x;

  8.    int run=1;

  9.    float three=0;

  10.    int rate;

  11.    cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;

  12.    cout<<"中獎規則說明:"<<endl;

  13.    cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;

  14.    cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;

  15.    cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;

  16.    cout<<"本次測試方式: 測試一百次, 並以百分比的方式表示中三獎, 全部欄位出現7的機率"<<endl;
  17.    
  18.    cout<<"輸入測試次數:"<<endl;
  19.    
  20.    cin>>x;
  21.    
  22.    srand(time(NULL));

  23.    while(run<=x)

  24.    {

  25.        a=rand()%10;

  26.        b=rand()%10;

  27.        c=rand()%10;

  28.        cout<<a<<" "<<b<<" "<<c<<endl;

  29.        if((a==7 && b==7 && c==7)||(a==7 && b==7 && c==7)||(a==7 && b==7 && c==7))

  30.        {

  31.             three++;

  32.        }

  33.        run++;

  34.    }

  35.    rate=three/100*100;

  36.    cout<<"在這"<<x<<"的測試中, 三獎中了"<<three<<"次, 中獎機率為"<<rate<<"%"<<endl;   

  37.    system("pause");

  38.    return 0;

  39. }
複製代碼

TOP

返回列表