📄 dieroll2.cpp
字号:
#include <iostream>using namespace std;#include "dice.h"#include "prompt.h"#include "tvector.h"// use vector to simulate rolling of two dice// Owen Astrachan, March 9, 1994, modified 5/2/99const int DICE_SIDES = 4;int main(){ int sum; int k; Dice d(DICE_SIDES); tvector<int> diceStats(2*DICE_SIDES+1); // room for largest dice sum int rollCount = PromptRange("how many rolls",1,20000); for(k=2; k <= 2*DICE_SIDES; k++) // initialize counters to zero { diceStats[k] = 0; } for(k=0; k < rollCount; k++) // simulate all the rolls { sum = d.Roll() + d.Roll(); diceStats[sum]++; } cout << "roll\t\t# of occurrences" << endl; for(k=2; k <= 2*DICE_SIDES; k++) { cout << k << "\t\t" << diceStats[k] << endl; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -