Am I right about this?

Started by
11 comments, last by quagmire 18 years, 6 months ago
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]
cout<<"cout<<'' this is my siggy''";
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]
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

}
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.
Gor435 - My Journal - MySpace - Facebook
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!
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?

- Jason Astle-Adams

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...
cout<<"cout<<'' this is my siggy''";
Start with English first, then learn C/C++.
Is that a joke? Or is my English bad?
cout<<"cout<<'' this is my siggy''";

This topic is closed to new replies.

Advertisement