Am I right about this?
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]
Huh?
[edit] 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]
[edit] 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]
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
}
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
}
Quote:Original post by quagmire
Heh 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.
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";
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!
Cheerio!
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?
quagmire, could you try to be a bit clearer in future please?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement