English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類
0

程式真的很難懂

以後希望你還能繼續指導我一下

感恩你囉~

2006-12-20 13:21:00 · 1 個解答 · 發問者 崔弟 3 in 電腦與網際網路 程式設計

1 個解答

#include
#include
using namespace std;
#define TOTAL 2000

int dice2(int p)
{ int sum;
if (rand() % 100 < p)
if (rand()>1) sum = 7;
else sum = 11;
else
switch (rand()%9)
{ case 0: sum = 2; break;
case 1: sum = 3; break;
case 2: sum = 12; break;
case 3: sum = 4; break;
case 4: sum = 5; break;
case 5: sum = 6; break;
case 6: sum = 8; break;
case 7: sum = 9; break;
case 8: sum = 10; break;
}
return sum;
}

int main()
{ int aaa, b1, b2, b3, p, i, sum;
cout << "請輸入一個0~100的機率值:";
cin >> p;
if (p > 100) p = 90;
if (p < 0) p = 10;
for (b1=b2=b3=i=0; i { sum = dice2(p);
if (sum == 7 || sum == 11) b1++;
if (sum == 2 || sum == 3 || sum == 12) b2++;
else b3++;
}
cout << "獲勝次數: " << b1 << "\t機率:" << (float)b1 * 100 / TOTAL
<< "\n輸掉次數: " << b2
<< "\n平手次數: " << b3 << '\n';
system("PAUSE");
return 0;
}

2006-12-20 21:49:39 補充:
吃 \的怪新知識
cout << "獲勝次數: " << b1 << "\t機率:" << (float)b1 * 100 / TOTAL
<< "\n輸掉次數: " << b2
<< "\n平手次數: " << b3 << '\n';

2006-12-20 16:47:47 · answer #1 · answered by ? 7 · 0 0

fedest.com, questions and answers