返回列表 發帖
本帖最後由 t2364705 於 2012-2-24 19:21 編輯
  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 three=0;
  10.     int rate=0;
  11.     cout<<"*** 吃角子老虎機中獎機率評估程式 ***"<<endl;
  12.    cout<<"中獎規則說明:"<<endl;
  13.    cout<<"任一欄出現3 --> 獎金變兩倍"<<endl;
  14.    cout<<"任兩欄出現3 --> 獎金變十倍"<<endl;
  15.    cout<<"三欄都出現3--> 獎金變一百倍"<<endl;
  16.    cout<<"本次測驗方式:測驗一百次,並以百分比的方式表示中三獎(任一欄位出現3)的機率"<<endl;
  17.    srand(time(NULL));
  18.    while(run<=100)
  19.    {
  20.    a=rand()%10;
  21.    b=rand()%10;
  22.    c=rand()%10;
  23.    cout<<a<<" "<<b<<" "<<c<<endl;
  24.    if((a!=3 && b!=3 && c==3)||(a==3 && b!=3 && c!=3)||(a!=3 && b==3 && c!=3))
  25.    {
  26.    three++;
  27.    }
  28.    run++;
  29. }
  30.    rate=three/run*100;         
  31.    cout<<"在這一百次測試中共中三獎"<<three<<"次,中獎率是" <<rate<<"%";   
  32. system("pause");   
  33. return 0;   
  34. }
複製代碼

TOP

返回列表