Sign in to follow this  
quagmire

Am I right about this?

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 this post


Link to post
Share on other sites
deavik    570
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]

Share this post


Link to post
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 this post


Link to post
Share on other sites
Gor435    426
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.

Share this post


Link to post
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 value

if(x < 10)
cout << "Hello, World!\n";
else if(x > 10)
cout << "World, Hello!\n";
else
cout << "HWeolrllod!\n";

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
MENTAL    383
Quote:
Original post by quagmire
Is that a joke? Or is my English bad?


Put it this way - THIS isn't good:

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?


:)

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this