• Advertisement
Sign in to follow this  

Am I right about this?

This topic is 4523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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


Link to post
Share on other sites
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
Guest Anonymous Poster
Start with English first, then learn C/C++.

Share this post


Link to post
Share on other sites
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
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
Sign in to follow this  

  • Advertisement