我创建了一个骰子博彩游戏。我无法正确地循环到 运行 有人可以帮我找到问题吗?

I have created a dice betting game. I cannot get the loop to run correctly could someone help me with finding the issue?

好的,所以我需要帮助让银行在每次循环运行后不重置为 100。我尝试了很多方法,但似乎无法让它发挥作用。你能帮我解释一下和举个例子吗?

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
using namespace std;

int displaystats(int gamesplayed, int wins, int losses, int bank);

int main()
{
    int bank = 100;//intital bank value
    int bet = 0;//desired wager
    int wins = 0;//games won
    int losses = 0;//games lost
    int gamesplayed = 0;//how many rounds you played
    int compdice1 = 0;//first rolled dice for computer
    int compdice2 = 0;//second rolled dice for computer
    int playdice1 = 0;//first rolled dice for player
    int playdice2 = 0;//seconds rolled dice for player
    int newdice = 0;//the dice to risk your wager
    int comproll = 0;//the sum of the computers roll
    int playroll = 0;//the sum of the players roll

    do
    {
        if (bank < 0)
        {
            cout << "You have " << bank << " coins in your bank." << endl;
            cout << "I am sorry you are out of money." << endl;
            displaystats(gamesplayed, wins, losses, bank);
            break;
        }

        else if (bank > 0)
        {
            cout << "You have " << bank << " coins in your bank." << endl;
            cout << "How many coins would you like to bet? ";
            cin >> bet;

            compdice1 = (rand() + time(0)) % 6 + 1;//computer dice
            compdice2 = (rand() + time(0)) % 6 + 1;//computer second dice
            playdice1 = (rand() + time(0)) % 6 + 1;//player dice
            playdice2 = (rand() + time(0)) % 6 + 1;//player second dice

            comproll = compdice1 + compdice2;//computer sum
            playroll = playdice1 + playdice2;//player sume

            cout << "Your roll was " << playdice1 << " and " << playdice2 << " with a sume of " << playroll << endl;

            if (playroll < comproll)
            {
                char option;//option to roll another dice


                cout << "You win!" << endl;
                cout << "Would you like to roll a third dice to earn 1.5 times your bet, yes or no? ";
                cin >> option;

                if (option == 'yes')
                {
                    int newroll;//the new sum of the three dice
                    int newdice;//the extra roll

                    newdice = (rand() + time(0)) % 6 + 1;
                    newroll = playroll + newdice;//the value of players roll

                    if (newroll > comproll)
                    {
                        cout << "The computer rolled " << comproll << endl;
                        cout << "You now rolled higher than the computer therefore, I am sorry you lose this round." << endl;
                        cout << "Your bank now equals " << bank - bet << endl;
                        losses++;
                        gamesplayed++;
                    }

                    else if (newroll < comproll)
                    {
                        cout << "You win!" << endl;
                        cout << "Your bank now equals " << bank + (1.5 * bet) << endl;
                        wins++;
                        gamesplayed++;
                    }
                }
                else if (option == 'no')
                {
                    cout << "Your bank now equals " << bank + bet << endl;
                    wins++;
                    gamesplayed++;
                }
            }

            else if (playroll > comproll)
            {
                cout << "The computer rolled " << comproll << endl;
                cout << "You rolled higher than the computer therefore, I am sorry you lose this round." << endl;
                cout << "Your bank now equals " << bank - bet << endl;
                losses++;
                gamesplayed++;
            }

            else if (playroll = comproll)
            {
                cout << "The computer also rolled " << comproll << endl;
                cout << "I am sorry you now lose double your bet!" << endl;
                cout << "Your bank now equals " << bank - (2 * bet) << endl;
                losses++;
                gamesplayed++;
            }
        }
    } while (bank > 0);

    int stats = displaystats(gamesplayed, wins, losses, bank);

    cout << "Your stats are " << stats << endl;
    return 0;
}

int displaystats(int gamesplayed, int wins, int losses, int bank)
{
    cout << "Games Played: " << gamesplayed << endl;
    cout << "Wins: " << wins << endl;
    cout << "Losses: " << losses << endl;
    cout << "Bank Total: " << bank << endl;

    return (gamesplayed, wins, losses, bank);
}

您与银行的问题 "resetting" 经常是您从未真正从银行扣除赌注。请参阅以下代码,希望对您有所帮助。

cout << "You have " << bank << " coins in your bank." << endl;
cout << "How many coins would you like to bet? ";
cin >> bet;


//This is the line that you forgot.
bank = bank - bet

如果您随后赢了,那么您可能想稍后将一些钱存回银行。 (但这取决于您。)我希望这会有所帮助。

编辑:

这里是完整代码的粘贴箱:http://pastebin.com/HzvRxjXL

此外,如果这解决了您的问题,请将其标记为答案,以免其他人花时间回答已解决的问题,我将不胜感激。

编辑 2:

这有一个(据我所知)固定和注释版本的代码。我希望这会有所帮助:http://pastebin.com/miQjy4B5