簡體   English   中英

如何跟蹤分數— C ++控制台

[英]How to keep track of a score — C++ Console

我正在用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;
}

使用for循環,而不是再次調用main() 當您調用main() ,局部變量將被重新初始化。

或者,使變量成為全局范圍(在main()之外聲明它們)。

在循環之前,從用戶“啟動資金”中讀取內容,然后在循環內部讀取下注並對該下注進行操作。 我猜循環應該重復讀取下注,直到用戶用完錢為止。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM