zoukankan      html  css  js  c++  java
  • 掷筛子游戏

    #include <iostream>
    #include<cstdlib>
    using namespace std;
    int roolDice()
    {
        int die1 = 1 + rand() %6;
        int die2 = 1 + rand() %6;
        int sum = die1 + die2;
        cout << "player rooled " << die1 << "+" << die2  << "=" << sum << endl;
        return sum;
    }
    enum    GameStatus{Win,Lose,PLAYING};
    
    int main()
    {
        int sum,mypoint;
        GameStatus status;
        unsigned seed;
        cout << "please enter an unsigned integer: ";
        cin >> seed;
        srand(seed);
        sum = roolDice();
        switch(sum){
        case 7:
        case 11:
            status = Win;
            break;
        case 2:
        case 3:
        case 12:
            status = Lose;
            break;
        default:
            status = PLAYING;
            mypoint = sum;
            cout << "point is " << mypoint << endl;
            break;
        }
        while(status == PLAYING)
        {
            sum = roolDice();
            if(sum == mypoint)
                status = Win;
            else if(sum % 7 == 0)
                status == Lose;
        }
        if(status == Win)
        {
            cout << "player wins" << endl;
        }
        else{
            cout << "player lose" << endl;
        }
        return 0;
    }
  • 相关阅读:
    【CF989E】A Trance of Nightfall
    [SHOI2012]信用卡凸包
    [HNOI2016]最小公倍数
    [HNOI2012]射箭
    [SCOI2015]小凸想跑步
    [CQOI2006]凸多边形
    ### Hadoop
    ### awk
    ### Theano
    ### Python Learning
  • 原文地址:https://www.cnblogs.com/zhangjialu2015/p/5330103.html
Copyright © 2011-2022 走看看