- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a, b, c;
- float run=1;
- int three=0;
- int rate;
- cout<<"$$$吃角子老虎機評估中獎機率程式$$$"<<endl;
- cout<<"~中獎規則說明~"<<endl;
- cout<<"任一欄出現一個7--> 獎金2倍 "<<endl;
- cout<<"任兩欄出現兩個7--> 獎金10倍 "<<endl;
- cout<<"三欄都出現7--> 獎金100倍 "<<endl;
- cout<<"本次測試方式 測試100次任一欄位出現7的機率用百分比的方式表示 "<<endl;
- srand(time(NULL));
- while(run<=100)
- {
- run++;
- 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/run*100;
- cout<<"在這100次中三獎的機率是"<<rate<<"%"<<"共中了"<<three<<"次"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |