本帖最後由 t2364705 於 2012-2-24 19:21 編輯
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a, b, c;
- int run=1;
- float three=0;
- int rate=0;
- cout<<"*** 吃角子老虎機中獎機率評估程式 ***"<<endl;
- cout<<"中獎規則說明:"<<endl;
- cout<<"任一欄出現3 --> 獎金變兩倍"<<endl;
- cout<<"任兩欄出現3 --> 獎金變十倍"<<endl;
- cout<<"三欄都出現3--> 獎金變一百倍"<<endl;
- cout<<"本次測驗方式:測驗一百次,並以百分比的方式表示中三獎(任一欄位出現3)的機率"<<endl;
- srand(time(NULL));
- while(run<=100)
- {
- a=rand()%10;
- b=rand()%10;
- c=rand()%10;
- cout<<a<<" "<<b<<" "<<c<<endl;
- if((a!=3 && b!=3 && c==3)||(a==3 && b!=3 && c!=3)||(a!=3 && b==3 && c!=3))
- {
- three++;
- }
- run++;
- }
- rate=three/run*100;
- cout<<"在這一百次測試中共中三獎"<<three<<"次,中獎率是" <<rate<<"%";
- system("pause");
- return 0;
- }
複製代碼 |