返回列表 發帖
  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,three=0;
  9.     int rate;
  10.     cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
  11.     cout<<"中獎規則說明:"<<endl;
  12.     cout<<"任一欄出現 7-->您投下的賭注成兩倍"<<endl;
  13.     cout<<"任兩欄出現 7-->您投下的賭注成十"<<endl;
  14.     cout<<"三欄現 7-->您投下的賭注成一百"<<endl;
  15.     cout<<"本次測試方式:測試100次中三獎的機率"<<endl;
  16.     while(run<=100)
  17.     {
  18.                    run++;
  19.                    a=rand()%10;  
  20.                    b=rand()%10;
  21.                    c=rand()%10;
  22.                    cout<<a<<" "<<b<<" "<<c<<endl;
  23.                    if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
  24.                    {
  25.                                three++;
  26.                    }
  27.                    run++;
  28.     }
  29.     rate=three/run*100;
  30.     cout<<"在這一百次中您的中獎機率是"<<rate<<"%"<<endl;
  31.    

  32.     system("pause");
  33.     return 0;   
  34. }
複製代碼

TOP

返回列表