Solved

Axter i need a little more help

Posted on 2004-10-10
6
184 Views
Last Modified: 2010-04-01
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
Comment
Question by:tedschnieders
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 12273364
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
 

Author Comment

by:tedschnieders
ID: 12273500
my teacher is anti microsoft so we just use a compiler and a cmd prompt i think the compiler is borland??
0
 
LVL 30

Expert Comment

by:Axter
ID: 12273700
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 17

Expert Comment

by:rstaveley
ID: 12274595
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
 
LVL 17

Expert Comment

by:rstaveley
ID: 12274607
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
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 12274652
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now