Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6908907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:37:19+00:00 2026-05-27T08:37:19+00:00

So on my final project, a black jack and poker simulator using inheritance from

  • 0

So on my final project, a black jack and poker simulator using inheritance from a cards class, we have to keep track of the user’s bet and total Money. However, in my code, it does very strange things. For example: if your total money was 1000000000 dollars and you bet 100 and won back 200 your new total money is now equal to 199 dollars

My program goes back and forth from doing this, and not doing this. It’s maddening and I don’t know why it’s happening. The following is my main function, and my two functions that handle each poker game. If anyone thinks more code is needed to answer, though I’ll gladly include class headers and implementation files. Thanks to all who may help! The following is my main functions, and the two functions to handle each game:

unsigned int handlePoker(unsigned int);
unsigned int handleBlackJack(unsigned int);
//main function:
//asks the user what game they want to play
//then calls a function for the appropriate
//game chosen
int main()
{//two choices:
//one for quitting the program
//the other for whichever game they want
    char yesOrNo;
    char choice;
    unsigned int totalMoney;
    cout<< "please enter a starting amount to bet with"<<endl;
    cin>>totalMoney;
    cout<<"would you like to play?"<<endl;
    cout<<"enter 'y' for yes and 'n' for no"<<endl;
    cin>>yesOrNo;
    do{
        //ask the user which game they want
        cout<<"would you like to play poker or black jack?"<<endl;
        cout<<"input '1' for poker and '0' for blackjack"<<endl;
        cin>>choice;
        if(choice == '1')
        {
            totalMoney = handlePoker(totalMoney);
        }//end if
        else if(choice == '0')
        {
            totalMoney = handleBlackJack(totalMoney);
        }//end else if
       else
       {
            cout<<"I'm sorry, the input you entered was invalid"<<endl;
            cout<<"please try again"<<endl;
            cin.clear();
        }//end else
        cout<<"would you like to try again?"<<endl;
        cout<<"('y' for yes, or 'n' for no)"<<endl<<endl;
        cin>>yesOrNo;
   }while(yesOrNo == 'y' || yesOrNo == 'Y'); //end do while loop
   return 0;
}//end int main


//handle poker:  
//a void function which takes an
//unsigned integer value
//the function declares a "poker" object
//and uses it's void functions to sim a poker game
unsigned int handlePoker(unsigned int tot)
{
    unsigned int multiply;
    unsigned int betMonies;
    unsigned int win;
    poker round;
    cout<<"how much do you want to bet?"<<endl;
    cin>>betMonies;
    //if the bet money entered was valid
    // we begin playing
    if(betMonies < tot)
    {//big if begin
        //ask if they want a better hand
        round.betterHand();

        //set the number we multiply your money by 
        multiply = round.rewardMoney();
        //if multiply is 0
        //then the user has lost this hand
        //we inform them as such, and subtract
        //their bet money from their total money
        if(multiply == 0)
        {
            cout<<"I apologize, but you seem to have lost"<<endl;
            cout<<"when you lose, your bet is subtracted"<<endl;
            cout<<"your initial balance was: "<<tot<<endl;
            //decrement the total
            tot = (tot - betMonies);
            cout<<"your new balance is: "<<tot<<endl;
        }//end if
    //if multiply is not 0 (assuming it's not negative
    //because there's no way it could be)
    //we tell them what they've won, and add it to
    //their total money
   else
   {
        win = (multiply*betMonies);
        cout<<"your initial balance was: "<<tot<<endl;
        cout<<"your win was"<<win<<endl;
        //increment the total
        tot = (win + tot);
        cout<<"your new balance is "<<tot<<endl;
    }//end else
}//big if end

//if the amount entered was not valid
//simply tell them, then run the loop again

else
{//else begin
    cout<<"I'm sorry, that was not a valid amount of money"<<endl;
    cout<<"please try again"<<endl;
}//end else
round.shuffleDeck();
return tot;

}//end handlePoker



//handle Black jack:
//a function returning an unsigned int
//that keeps track of the total money
//declares a black jack object
//and uses it's member functions to play black jack

unsigned int handleBlackJack(unsigned int tot)
{
blackJack play;
unsigned int reward;
unsigned int betMoolah;

//ask the user for the bet they want
cout<<"how much do you want to bet?"<<endl;
cin>>betMoolah;

//if the bet is less than the total passed by reference
//then we can start running the game 
if(betMoolah < tot)
{

    //print the hands dealt in the constructor
    play.printHands();

    //run the function that lets them hit or stay
    //the function contains a do while loop
    // so, no looping is required
    play.hitOrStay();

    //we then handle the reward
    //which returns an integer type
    reward = play.handleReward(betMoolah);

    //prints dealer and player's hands fully
    play.printHandGame();

    //in one of the cases, reward is set to -1
    //we use this here:
    if(reward < 0 )
    {
        //if the reward is negative, then
         //we subtract the bet money
        //then we tell the user their new balance
        cout<<"your balance was "<<tot<<endl;
        cout<<"you have lost, so your bet is subtracted"<<endl;
        tot = (tot-betMoolah);
        cout<<"your new balance is: "<<tot<<endl;
     }//end if



     //if the reward is above 0, then we add the reward to the total
     else if(reward > 0)
     {
        cout<<"your original balance was "<<tot<<endl;
        cout<<"your winnings are: "<< reward<<endl;
        tot = reward + tot;
        cout<<"your new balance is: "<<tot<<endl;
    }//end else

    else
    {
        cout<<"you have lost no money"<<endl;
        cout<<"your balance is still " <<tot<<endl;
    }

}//end of the big if



 //if the amount of money entered is above total money
 //then the money entered isn't valid at all
else
{
    cout<<"the amount of money you've entered is not valid"<<endl;
    cout<<"please try again"<<endl;
}// end else
play.shuffleDeck();
return tot;

}//end handleBlackJack
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:37:19+00:00Added an answer on May 27, 2026 at 8:37 am

    I can’t fully explain what your seeing, but I did notice a liberal use of unsigned int. In particular, in handleBlackJack you have:

    unsigned int reward;
    

    and then

    reward = play.handleReward(betMoolah);
    

    and finally

    if(reward < 0 )
    

    If reward can be negative, it shouldn’t be an unsigned int. As others have suggested, step through it in a debugger and “follow the money”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 weeks to finish my final year project.I need a GUI IDE
I'm using Hibernate for a personal project. In my project, I have these directory:
I am working on a final project for class and am having a little
This is my final semester project. I have no knowledge of mobile application development.My
I'm doing another Java project for my class. In this assignment, we have to
The ASP.NET MVC 1.0 (final) project template has basic membership built in, but I
I am doing an undergrad final project, and need to justify my choice of
As a part of my final year university project I am designing a social
So I'm working on a Black jack program and I'm a little stuck. I'll
Currently i'm working on my final year project. In a webpage which loads data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.