Server Help

Non-Subspace Related Coding - problem with a switch statement

Anonymous - Sat Dec 23, 2006 3:43 pm
Post subject: problem with a switch statement
for some reason when i compile it , it ingores the swith (chp)

Code: Show/Hide
   switch (choice)
   {
           case 1:
                cout<<"Your attack has caused opponent : ";
                int attack, damage;
                time_t seconds;
                time(&seconds);
                srand((unsigned int) seconds);
                attack = rand() % (HIGH - LOW + 1) + LOW;
                cout<<attack<<" damage!";
                damage = rand() % (HIGH - LOW + 1) + LOW;
                cout<<"\n\n\nYour Opponent attacked you with "<<damage<<" damage!\n\n";
                system("pause");   
               
                int chp, mhp;                             //curent hp, minus hlp
                mhp = damage - attack;
                chp = hp - mhp;
               
                switch (chp)
                {
                       case 1:
                       case 2:
                       case 3:
                       case 4:
                       case 5:
                       case 6:
                       case 7:
                       case 9:
                       case 10:
                            cout<<"yo";
                            break;
                }
               
                break;
               
                       
           default:
                   cout<<"\n\n Well there is only one function to press and its 1 and you fucked it all up so do i all over again\a\a";
                   break;
    }

Anonymous - Sat Dec 23, 2006 3:45 pm
Post subject:
oh and also i did define

#define hp 10
Mine GO BOOM - Sat Dec 23, 2006 3:49 pm
Post subject:
Use a debugger or a print statement before or after the switch statement to print the value of chp. My guess, it isn't 1,2,..,or 10.
Cyan~Fire - Sat Dec 23, 2006 4:20 pm
Post subject:
Don't seed the random number more than once. It's more random if you seed it once then keep randomizing it.
Anonymous - Sat Dec 23, 2006 9:42 pm
Post subject:
is it possible to make a switch state ment say a>b ?
Mine GO BOOM - Sun Dec 24, 2006 12:09 am
Post subject:
hellslaker wrote:
is it possible to make a switch state ment say a>b ?

Code: Show/Hide
if (a>b)
{
   printf("a (%d) > b (%d)\n", a, b);
}
else
   switch (a)
   {
      case 1:
         printf("a <= b (%d), and a is 1\n", b);
         break;
      default:
         printf("a (%d) <= b (%d), and a is not 1\n", a, b);
         break;
   }

Switch statements should be treated as hard-coded if statements. If you want something fancier for switch statements, use if instead.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group