Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Axter i need a little more help

hey thanks for helpen me
can you tell me what i need to do to keep this program running cause i cant get to the else if on my switch statment and i can't keep track of my money
thank you
ted
while(TotalMoney <= 0){

srand(time(0));
Dice1 = 1 + rand() % 6;
Dice2 = 1 + rand() % 6;


SumOfDice = Dice1 + Dice2;




      
TotalMoney = 1000;
Counter = ++Counter;

cout << Dice1 << endl;
cout << Dice2 << endl;


switch(SumOfDice){

case 2:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
break;
      }
      else if(Counter < 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }
case 3:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
break;
      }
      else if(Counter < 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }

case 4:      
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;      
      }
      else if(Counter < 1){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
break;
      }
case 5:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;      
      }
      else if(Counter < 1){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
break;
      }
case 6:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;
      }      
      else if(Counter < 1){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
break;
      }
case 7:
      if(Counter == 1){
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
break;
      }
      else{
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
break;
      }
case 8:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;
      }
      else if(Counter < 1){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
break;
}
case 9:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;
      }
      else if(Counter < 1){
      TotalMoney = TotalMoney + Bet;
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;      

break;
      }
case 10:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
break;      
      }
      else if(Counter < 1){
      TotalMoney = TotalMoney + Bet;
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;      
break;
      }
case 11:
      if(Counter == 1){
      TotalMoney = TotalMoney + Bet;
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
break;      
      }
      else{
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }
case 12:
      if(Counter == 1){
      TotalMoney = TotalMoney - Bet;
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
break;
      }
else if(Counter < 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;

break;
}      
switch(Dice1){

case 1:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "\n***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
}      
switch(Dice2){

case 1:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
      }                  
      
      return 0;


}    
      }
            }
0
tedschnieders
Asked:
tedschnieders
1 Solution
 
AxterCommented:
What compiler are you using?

You should try using your debugger, and run through your code step by step, until you get to the problem in your code.

You can then view the variables, and see what are their values.

0
 
tedschniedersAuthor Commented:
my teacher is anti microsoft so we just use a compiler and a cmd prompt i think the compiler is borland??
0
 
AxterCommented:
If you don't have a debugger, what you can do, is output variables through your code.

Which else statement are you having problems with specifically?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rstaveleyCommented:
Not relevant to your question, but I notice that you are seeding your random number generator inside the while loop on time(NULL). If you do two rolls in the same second, you'll get the same numbers. Better to seed it outside the loop just the once.
0
 
rstaveleyCommented:
Are you aware also that you are assigning TotalMoney = 1000 inside the while loop. I expect you want the total money to change... unless that's for the sake of debugging the application.
0
 
itsmeandnobodyelseCommented:
I compiled your prog after doing some minor changes but there are a lot of lines that cannot work:

>> while(TotalMoney <= 0){

That loop will never start if TotalMoney is greater 0. Change to:
   
    TotalMoney = 1000;
    while (TotalMoney > 0){  

>> srand(time(0));

Don't seed the rand function in the loop as time(0) only has a resolution of 1 second. So, most likely you will get the same rand() numbers again. Move the srand statement above the loop.

>> TotalMoney = 1000;

Same applies to that: you have to move it above the while loop or you'll never have a break;

>> if(Counter == 1)

Actually i don't know what do you want to do with that variable. It's never initialized and incremented in the loop, but you are checking the variable on 1 or < 1, both normally is false.

>> case 1:

The SumOfDice never can be 1;

>> case 2:
>> if(Counter == 1){
>>  ...  break;
>>  }
>> elseif (Counter < 1){
>>  ... break;
>> }
>> case 3:

If Counter > 1 there is no break. So, it falls thru to case 3:, case 4:, ...

Add a break at end of any case.

>> case 12:
>>      if (..) {
>>      ...
>>      break;
>>      }
>>  switch(Dice1){
     
the switch(Dice1) is within the previous switch block (SumOfDice9. I suppose, you have to close the previous switch *before* starting the new switch statements.

Regards, Alex

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now