返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a, b, c;
  8.     float run=1;
  9.     int three=0;
  10.     int rate;
  11.     cout<<"$$$吃角子老虎機評估中獎機率程式$$$"<<endl;
  12.     cout<<"~中獎規則說明~"<<endl;
  13.     cout<<"任一欄出現一個7--> 獎金2倍 "<<endl;
  14.     cout<<"任兩欄出現兩個7--> 獎金10倍 "<<endl;
  15.     cout<<"三欄都出現7--> 獎金100倍 "<<endl;
  16.     cout<<"本次測試方式 測試100次任一欄位出現7的機率用百分比的方式表示 "<<endl;
  17.     srand(time(NULL));   
  18.     while(run<=100)
  19.     {
  20.         run++;
  21.         a=rand()%10;
  22.         b=rand()%10;
  23.         c=rand()%10;
  24.         cout<<a<<" "<<b<<" "<<c<<endl;  
  25.         if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
  26.         {
  27.                  three++;
  28.         }
  29.            run++;
  30.     }
  31.     rate=three/run*100;
  32.     cout<<"在這100次中三獎的機率是"<<rate<<"%"<<"共中了"<<three<<"次"<<endl;      
  33.   system("pause");   
  34.   return 0;
  35. }
複製代碼

TOP

返回列表