rollsum.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 26 行

CPP
26
字号
#include <iostream>using namespace std;#include "dice.h"#include "prompt.h"// simulate rolling two dice to obtain specified sum// Owen Astrachan, 8/9/94int main(){    Dice d1(6);          // define two dice    Dice d2(6);    int numRolls = 1;    // # of times dice are rolled    int targetSum = PromptRange("enter target to roll:",2,12);        while (d1.Roll() + d2.Roll() != targetSum)    {        numRolls += 1;    }    cout << "number of rolls needed to get " << targetSum         << " = " << numRolls << endl;    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?