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 6682635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:43:46+00:00 2026-05-26T04:43:46+00:00

It is strange, I coded my pig game here in c++ which once the

  • 0

It is strange, I coded my pig game here in c++ which once the user or computer reaches 100 he wins. But the problem is if I keep rolling and I go past 100 I don’t win unless I hold after I get there. And the computer if it gets close to 100 around 80 to 100 it will just say it wins. I don’t understand whats going on here and what the problem is? I did everything right! Or am I missing something?

How can I fix this issue where once I reach 100 rolling or holding on the users end that it just wins and doesn’t go past 100 so if I hold at 100+ it tells me I win. How can I go about making it so the computer only wins when it actually gets to 100 or past it automatically?

  • 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-26T04:43:47+00:00Added an answer on May 26, 2026 at 4:43 am

    Try it this way :

                do
                {
                   if((humanTotalScore < 100) && (computerTotalScore < 100))
                   continuePlay = true;
                   else
                   continuePlay = false;
    
                    {
    
                        humanTurn(humanTotalScore);
                        computerTurn(computerTotalScore);
                    }
    
    
                    if(humanTotalScore >= 100)
                    {
                        cout << "You won!";
                        return 0;
                    }
                    else if (computerTotalScore >= 100)   
                    {
    
                        cout << "You lost!";
                        return 0;
                    } 
               }
                 while(continuePlay == true);
    

    and

    int computerTurn(int& computerTotalScore)
        {
                int currentScore = 0;
                int randomDiceRoll;
                cout << " " << endl;
                cout << "The computer will now make its move" << endl;
                cout << " " << endl;
                while ((currentScore < 20) && (computerScore != 1)&&computerTotalScore<100)
                {
                        randomDiceRoll = diceRollFunction();
                        if (randomDiceRoll == 1)
                        {
                                cout << "The computer rolled: ";
                                cout << randomDiceRoll;
                                cout << " " << endl;
                                cout << "The computers total score is: " << computerTotalScore;
                                cout << " " << endl;
                                cout << " " << endl;
                                cout << "The computer has rolled a one, it is now your turn." << endl;
                                cout << " " << endl;
    
                                break;
                        }
                        else
                        {
                                currentScore += randomDiceRoll;
                                computerTotalScore += randomDiceRoll;
                                cout << "The computer rolled: ";
                                cout << randomDiceRoll;
                                cout << " " << endl;
                                cout << "The computers total score is: " << computerTotalScore;
                                cout << " " << endl;
                                cout << " " << endl;
                        }
                }
                if(currentScore >= 20)
                {
                        computerTotalScore += computerScore;
                        cout << "The computer has reached a max of 20 points for their turn" << endl;
                        cout << " " << endl;
                }
    
                return computerTotalScore;
        }
    

    changes made :

    • The if condition was altered due to flaw in logic.
    • The If condition,if((humanTotalScore < 100) && (computerTotalScore < 100)) was moved into the do-while loop. Since it have to be updated each time anyone plays.
    • The function int computerTurn(int& computerTotalScore) was altered,In some places computerScore was used instead of computerTotalScore
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem in my android app. I have an activity which
I seem to have a strange problem: I coded an application in C++ (using
I have some strange problem. I think I followed documentation correctly but my code
EDIT - The code looks strange here, so I suggest viewing the files directly
This is really strange but this code is working fine unless the value entered
I come into a strange problem in pthread programming I've compiled the following code
I'm having a strange problem with the Google Calendar API (through PHP with Zend_Gdata.)
I am making some code , But it is so strange that code just
Strange Question i guess but i have this bit of code in my page...
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying

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.