返回列表 發帖
本帖最後由 劉漢文 於 2012-3-13 20:23 編輯
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     float rate[4];
  8.     int run=1;
  9.     int test;
  10.     int a, b, c;
  11.     float one=0 ,two=0 ,three=0 ,four=0;
  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>>test;
  20.    srand(time(NULL));
  21.    while(run<=test)
  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.        if(a!=7 && b!=7 && c!=7)
  40.        {
  41.             four++;
  42.        }
  43.        run++;
  44.    }
  45.    cout<<"在這"<<test<<"次的測試中,三獎中了"<<three<<"次,二獎中了"<<two<<"次,第一特獎中了"<<one<<"次"<<endl;
  46.    rate[0]=three/test*100;
  47.    rate[1]=two/test*100;
  48.    rate[2]=one/test*100;
  49.    rate[3]=four/test*100;
  50.    cout<<"中三獎任一欄出現7的機率約為"<<rate[0]<<"%"<<endl;
  51.    cout<<"中二獎任兩欄出現7的機率約為"<<rate[1]<<"%"<<endl;
  52.    cout<<"中第一特獎三欄都出現7的機率約為"<<rate[2]<<"%"<<endl;
  53.    cout<<"都沒中獎的機率為"<<rate[3]<<"%"<<endl;
  54.    system("pause");
  55.    return 0;
  56. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     float rate[3];
  8.     int run=1;
  9.     int test;
  10.     int a, b, c;
  11.     float one=0 ,two=0 ,three=0;
  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>>test;
  20.    srand(time(NULL));
  21.    while(run<=test)
  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<<"在這"<<test<<"次的測試中,三獎中了"<<three<<"次,二獎中了"<<two<<"次,第一特獎中了"<<one<<"次"<<endl;
  42.    rate[0]=three/test*100;
  43.    rate[1]=two/test*100;
  44.    rate[2]=one/test*100;
  45.    cout<<"中三獎任一欄出現7的機率約為"<<rate[0]<<"%"<<endl;
  46.    cout<<"中二獎任兩欄出現7的機率約為"<<rate[1]<<"%"<<endl;
  47.    cout<<"中第一特獎三欄都出現7的機率約為"<<rate[2]<<"%"<<endl;
  48.    system("pause");
  49.    return 0;
  50. }
複製代碼

TOP

返回列表