- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a, b, c;
- int run=1;
- float three=0;
- int rate ,test;
- cout<<"$$$ 吃角子老虎機中獎機率評估程式 $$$"<<endl;
- cout<<"中獎規則說明:"<<endl;
- cout<<"任一欄出現7 --> 獎金變兩倍"<<endl;
- cout<<"任兩欄出現7 --> 獎金變十倍"<<endl;
- cout<<"三欄都出現7 --> 獎金變一百倍"<<endl;
- cout<<"本次測試方式: 讓使用者輸入欲測的次數 並以百分比的方式表示中三獎, 任一欄位出現7的機率"<<endl;
- cout<<"請輸入測的次數:";
- cin>>test;
- srand(time(NULL));
- while(run<=test)
- {
- a=rand()%10;
- b=rand()%10;
- c=rand()%10;
- cout<<a<<" "<<b<<" "<<c<<endl;
- if((a==7 && b!=7 && c!=7)||(a!=7 && b==7 && c!=7)||(a!=7 && b!=7 && c==7))
- {
- three++;
- }
- run++;
- }
- rate=three/test*100;
- cout<<"在這"<<test<<"次的測試中, 三獎中了"<<three<<"次, 中獎機率為"<<rate<<"%"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |