## Recommended Posts

quagmire    194
Ha ha. Switch Case isn't so hard. Ok well I'm not sure if the example I want to use is easy. You'd need some OOP probably. But it is like instead of using if, if, if, and if. It is sorta like the actions of a hand.(my example is) case: 1 might be grab and case:2 might be make fist, etc. Am I right? [Edited by - quagmire on October 7, 2005 8:20:24 PM]

##### Share on other sites
deavik    570
Huh?

 I couldn't understand anything of what you were trying to say, and I'll be darned if others can. Are you trying to use a switch statement instead of multiple if 's, is that it? You really shouldn't post if you are this sleepy! [lol] [/edit]

##### Share on other sites
nprz    692
Do you mean something like this?

enum { HAND = 0, GRAB = 1 };

// in the function
switch (input)
{
case HAND:
// code for hand
break;
case GRAB:
// code for grab
break;
default:
// not handled input

}

##### Share on other sites
Gor435    426
Quote:
 Original post by quagmireHeh heh. Not so hard. Ok well I'm not sure if the ex. I want to use, you'd need some OOP probly. But it is like instead of using if if if and if. hand case 1 might be grab, 2 might be make fist, etc. Am I right?

Ok a little confusing. Yes a case statement is like using multiple if statments to check the same intregral value for different situations.

example:
#include <iostream>using std::cout;using std::cin;using std::endl;int main(){  int numtocheck = 0;  cout<< "Please enter a number from 1 to 3" << endl;  cin>> numtocheck;  switch(numtocheck)  {    case 1: //this is equivalent to if(numtocheck == 1)     cout<< "You entered 1" << endl;     break;    case 2: //this is equivalent to if(numtocheck == 2)     cout<< "You entered 2" << endl;     break;    case 3: //this is equivalent to if(numtocheck == 3)     cout<< "You entered 3" << endl;     break;    default: //this is equivalent to if(numtocheck != 1 &&             //numtocheck != 2 && numtocheck != 3)     cout<< "The number you entered is not from 1 to 3" << endl;     break;  }  return 0;}

{Edit}Also looks at nprz's post he is saying the same thing but he is using your example.

##### Share on other sites
Krisc    494
I would like to note that you can also use else if statements instead of reusing an if statement.

int x;// x gets some valueif(x < 10)     cout << "Hello, World!\n";else if(x > 10)     cout << "World, Hello!\n";else     cout << "HWeolrllod!\n";

##### Share on other sites
deavik    570
I was right about the switch statements then, I guess. quagmire, nprz's example should have explained everything clearly, if not just post back. And I was feeling bad about my first post, please don't misunderstand it as trying to poke fun; I think everyone agrees your thread starter was a little hard to understand.

Cheerio!

##### Share on other sites
I have no idea how you guys figured out what the question is in this one.

quagmire, could you try to be a bit clearer in future please?

##### Share on other sites
quagmire    194
Sure everyone, I will try to be clearer. I was confused at the moment. I think everyones posts helped me. Thanks guys. Well, off to harder things in this bloody language. I will practice this. I will make a short program...

##### Share on other sites
Guest Anonymous Poster

##### Share on other sites
quagmire    194
Is that a joke? Or is my English bad?

##### Share on other sites
MENTAL    383
Quote:
 Original post by quagmireIs that a joke? Or is my English bad?

Put it this way - THIS isn't good:

Quote:
 Original post by quagmireHeh heh. Not so hard. Ok well I'm not sure if the ex. I want to use, you'd need some OOP probly. But it is like instead of using if if if and if. hand case 1 might be grab, 2 might be make fist, etc. Am I right?

:)

##### Share on other sites
Boku San    428
Just curious...could you repost/edit the original post, now that your English deficiency seems to have cleared up?

I don't understand it either, and I thought it was a misplaced response.

##### Share on other sites
quagmire    194
Sure. Sorry guys. I was just tired at the time. *Goes to edit first post*