user2872571
user2872571

Reputation:

How to keep track of a score -- C++ Console

I am making a poker game in C++ for a my intro to C++ class (should tell you that I am only a beginner so please excuse any bad programmer practice here). I am currently working on the betting system, in which I am quite pleased it does what I need it to do. Except that it doesn't carry on - the game just resets after the hand. Here's my code, I was thinking I need to make separate classes and then call those classes in the main, but I'm just not sure how that would be any different, if that's the case then I'll delete this question.

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

Upvotes: 0

Views: 2901

Answers (2)

Dialecticus
Dialecticus

Reputation: 16761

Read from user "start money" before the loop, and then inside the loop read the bet and do something with the bet. I guess the loop should repeat reading the bets until the user runs out of money.

Upvotes: 0

rkh
rkh

Reputation: 863

Use a for loop instead of calling main() again. When you call main(), the local variables are re-initialized.

Alternatively, make the variables global scope (declare them outside of main()).

Upvotes: 1

Related Questions