0

我正在为我的 C++ 课程介绍用 C++ 制作一个扑克游戏(应该告诉你我只是一个初学者,所以请原谅这里有任何不好的程序员练习)。我目前正在开发投注系统,我很高兴它完成了我需要它做的事情。除了它不继续 - 游戏只是在手后重置。这是我的代码,我在想我需要创建单独的类,然后在主类中调用这些类,但我只是不确定这会有什么不同,如果是这样的话,我会删除这个问题。

{// ConsoleApplication71.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "Bet.h"
using namespace std; 

//Bet P = int betP(int money);

int main()
{
bool win;
bool lose;
int Omoney = 100;
int money = 0;
int Tmoney = 0;
int bet = 0;
int earn = (bet * 2) + Omoney;

int loseM = 0;
loseM = loseM + bet;


cout << "Your start money = " << Omoney << " \n\n\n" << endl;
cout << "Place your bet here!" << endl;
cin >> bet;

money = Omoney - bet;
cout << "Your total money after bet is " << money << "\n\n";


//betP(int money)
//{
//  money - bet = money;
//}
if (bet > 10)
{
    win = true;
    if (win = true)
    {
        cout << "YOU WIN! \n\n" << endl;
        /*earn = (earn) + Omoney;*/
        cout << "You earned: \n" << earn;
        Tmoney = earn + (Omoney - bet);
        cout << "\nTotal money: \n" << Tmoney;
    }
}
else if (bet <= 10)
{
    lose = true;
    if (lose = true)
    {
        cout << "You Lose!\n\n\n" << endl;
        int Mlose= loseM + bet;
        cout << "You lost: \n" << Mlose;
        Tmoney = loseM + (Omoney - bet);
        cout << "\nTotal money: \n" << Tmoney;
        cout << "\n\n\n\n";
        Omoney = Tmoney;
        main();
    }
}


cin.get();
cin.get();
return 0;
}
4

2 回答 2

1

使用 for 循环而不是main()再次调用。当您调用main()时,局部变量会重新初始化。

或者,使变量成为全局范围(在 main() 之外声明它们)。

于 2013-11-06T16:39:25.250 回答
0

在循环之前从用户“start money”读取,然后在循环内读取赌注并用赌注做一些事情。我猜循环应该重复读取赌注,直到用户用完钱。

于 2013-11-06T16:49:32.083 回答