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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:32:46+00:00 2026-05-29T23:32:46+00:00

I have this code for a simple Dice throwing program with betting units and

  • 0

I have this code for a simple Dice throwing program with betting units and everything… you bet, if you get it right you get the amount u bet times the amount of dice you chose… if you’re wrong but by a little (in the range of the number you picked +- the number of dice u picked) you don’t lose anything, and if you’re really off you lose…

I have a while loop that basically keeps 2 things in mind: as long as the user either has BUs or if they didn’t type “no” or “No” for the try again… but for some reason it just doesn’t work… lol. any ideas why? the betting system works, it recognizes that betting.currentBU == 0, but the while loop just won’t react lol.

#include <iostream>
#include <string>
#include <cstdlib>
#include <time.h>
#include <limits>

using namespace std;

struct Dices{ // structure containing all the dice related integers
    int dice;
    int total;
    int  choice;
} Dices = {0,0,0};

struct betting{ // structure containing all the betting integers
    int currentBU;
    int bettedBU;
} betting = {100, 0};


int DiceThrow(int dicechoice, int totalnum){ // a method for the dice being rolled
    for(int i=1; i <= dicechoice;i++){
            totalnum = totalnum + (rand() % 6 + 1); //total number, repeated by the loop for every dice
        }
    return totalnum;
}

int winningbet(int dicea, int cBU, int bBU){ // in case the user guesses it right
    std::cout << "Congratulations, you got it right! \n";
    cBU = cBU + (dicea * bBU); // give him money...
    return(cBU);
}
int losingbet(int dicen, int totaln, int choicen, int cBU2, int bBU2){ //in case the user guesses wrong 
    if(choicen > (totaln+dicen) || choicen < (totaln+dicen)) // checks how wrong he is, if he's too off, he loses BUs
        cBU2 = cBU2-bBU2;
    else
        std::cout << "you we're so close, you don't lose any BUs! \n"; //if he was really close, just let him know he was close
    return(cBU2);

}

int main(){
    string decision; // decision if they want to keep playing or not
    srand ( (unsigned int)time(NULL) );
    while(decision != "no" || decision != "No" || betting.currentBU != 0) // makes sure of the decision AND that he still has BUs
    {
        Dices.total = 0;
        std::cout << "how many dice would you like to use? ";
        std::cin >> Dices.dice;
        std::cout << "how many How many BUs are you betting?(" << betting.currentBU << " BUs left) ";
        std::cin >> betting.bettedBU;
        if(betting.bettedBU > betting.currentBU){ // if he doesn't have enough BUs
            std::cout << "Sorry, you don't have that many BUs...";
            std::cout << "Want to try again with a different amount?(Yes/No) ";
            std::cin >> decision;
        }
        else{
            std::cout << "guess what number was thrown: ";
            std::cin >> Dices.choice;
            Dices.total = DiceThrow(Dices.dice, Dices.total);
            if(Dices.choice == Dices.total){
                betting.currentBU = winningbet(Dices.dice, betting.currentBU, betting.bettedBU);
                std::cout << "Want to try again?(Yes/No) ";
                std::cin >> decision;
            } else{
                std::cout << "Sorry, the number was " << Dices.total << "... better luck next time \n" ;
                betting.currentBU = losingbet(Dices.dice, Dices.total, Dices.choice, betting.currentBU, betting.bettedBU);
                if(betting.currentBU > 0){
                    std::cout << "Want to try again?(Yes/No) ";
                    std::cin >> decision;
                }
             }

        }
    }
    if(betting.currentBU == 0){
        std:cout << "sorry, you ran out of BUs...";
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
    }
    else{
        std::cout << "your final BU count is: " << betting.currentBU << "\n";
        std::cout << "Thanks for playing, see you next time! (Press ENTER to terminate...)";
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
    }
    return 0;

}
  • 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-29T23:32:47+00:00Added an answer on May 29, 2026 at 11:32 pm

    isn’t it supposed to be:

    while(decision != "no" && decision != "No" && betting.currentBU != 0) 
    

    We need to check if decision not equal to “no” AND not equal to “No” AND the currentBU not equal to 0

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

Sidebar

Related Questions

i have this simple code i just can't get it working. <html> <head> <script
Possible Duplicate: How to get nth jQuery element I have this simple code: <ul>
I have this simple code that needs to get a chunk of a large
I have this simple code, that makes a get to a webservice. For some
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I am a total beginner in JS/XML. I have this simple code that needs
There is probably is simple fix for this but I currently have code similar
I've wrote this simple piece of code. And I have a slight problem with
I have this simple code: <html> <head> <script src=jquery-1.5.1.min.js type=text/javascript></script> <script type=text/javascript> $(function() {
I have this simple jQuery code to test out. <html> <head> <script type=text/javascript src=jquery.js></script>

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.