craps.cpp

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

CPP
59
字号
#include <iostream>using namespace std;#include "dice.h"// simulate one games of craps (rules from W. Weaver, Lady Luck, 1982// Doubleday Press --- as given in Charles Whitney, Random Process in// Physical Systems, 1990, Wiley Interscience)//// written 5/17/94, modified 6/21/95, modified 4/19/99// prototypesint RollTwo();int main(){    int sum;    int point = RollTwo();                     // initial point        switch (point)    {      case 7:      case 11:        cout << "natural winner!!" << endl;        break;      case 2:      case 3:      case 12:        cout << "craps!! a loser" << endl;        break;      default:        while (true)        {            sum = RollTwo();            if (sum == point)            {   cout << "got your point! a winner" << endl;                break;            }            if (sum == 7)            {   cout << "loser, lost going for " << point << endl;                break;            }        }    }        return 0;}int RollTwo()//postcondition: returns sum of rolling two dice//               prints values rolled     {    Dice d(6);    int first = d.Roll();    int second = d.Roll();    cout << "rolling ... " << first << " " << second << endl;    return first + second;}

⌨️ 快捷键说明

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