Solved

# Axter i need a little more help

Posted on 2004-10-10
195 Views
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
Question by:tedschnieders
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 30

Expert Comment

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

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

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

LVL 17

Expert Comment

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

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

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

Question has a verified solution.

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

### Suggested Solutions

convert char array to number in c 5 93
c++ getting the first 10 characters of a char* string 11 111
Create a path if not exists 7 124
Adding items to a C# list incrementally 5 82
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generatâ€¦
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more â€¦
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
###### Suggested Courses
Course of the Month7 days, 6 hours left to enroll