如何跟踪分数 - C ++控制台

时间:2013-11-06 16:34:28

标签: c++ console

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

{// 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;
}

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

在循环之前从用户“开始金钱”中读取,然后在循环内部读取赌注并对赌注做一些事情。我想循环应该重复读取赌注,直到用户用完钱。