返回列表 發帖
  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.    
  12.    int test;
  13.    cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
  14.    cout<<"中獎規則說明:"<<endl;
  15.    cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;
  16.    cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;
  17.    cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;
  18.    cout<<"本次測試方式: 讓使用者自行輸入欲測試的次數, 並以百分比的方式分別表示出中第一特獎, 二獎與三獎的機率."<<endl;
  19.    cout<<"請輸入測的次數:";
  20.    cin>>test;
  21.    srand(time(NULL));
  22.    while(run<=test)
  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.        run++;
  41.    }
  42.    cout<<"在這"<<test<<"次的測試中, 三獎中了"<<three<<"次, 二獎中了"<<two<<"次,第一特獎中了"<<one<<"次"
  43.    <<endl;
  44.     rate[0]=three/test*100;
  45.     rate[1]=two/test*100;
  46.     rate[2]=one/test*100;
  47.     cout<<"中三獎一任意欄出現7的機率約為"<<rate[0]<<"%"<<endl;
  48.     cout<<"中二獎二任意欄出現7的機率約為"<<rate[2]<<"%"<<endl;
  49.     cout<<"中一獎三任意欄出現7的機率約為"<<rate[1]<<"%"<<endl;
  50.    //rate=three/test*100;
  51.    //cout<<"在這"<<test<<"次的測試中, 三獎中了"<<three<<"次, 中獎機率為"<<rate<<"%"<<endl;   
  52.    system("pause");
  53.    return 0;
  54. }
複製代碼

TOP

返回列表