Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
problem with a switch statement

 
Post new topic   Reply to topic Printable version
 View previous topic  my second project =) Post :: Post File Creator  View next topic  
Author Message
hell0-hacker21313
Guest


Offline

PostPosted: Sat Dec 23, 2006 3:43 pm    Post subject: problem with a switch statement Reply to topic Reply with quote

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;
    }
Back to top
hellzlaker4646545
Guest


Offline

PostPosted: Sat Dec 23, 2006 3:45 pm    Post subject: Reply to topic Reply with quote

oh and also i did define

#define hp 10
Back to top
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:40
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3614
Location: Las Vegas
Offline

PostPosted: Sat Dec 23, 2006 3:49 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Send email
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Dec 23, 2006 4:20 pm    Post subject: Reply to topic Reply with quote

Don't seed the random number more than once. It's more random if you seed it once then keep randomizing it.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
hellslaker
Guest


Offline

PostPosted: Sat Dec 23, 2006 9:42 pm    Post subject: Reply to topic Reply with quote

is it possible to make a switch state ment say a>b ?
Back to top
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:40
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3614
Location: Las Vegas
Offline

PostPosted: Sun Dec 24, 2006 12:09 am    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Send email
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 746 page(s) served in previous 5 minutes.

phpBB Created this page in 0.443215 seconds : 31 queries executed (93.7%): GZIP compression disabled