Solved

Axter i need a little more help

Posted on 2004-10-10
6
190 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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