Switch : it's like if and else if statement, but it is a lot more organized to work with and read
int main()
{
using namespace std;
int x;
cout<<"how many legs do you have"<<endl;
cin>>x;
switch (x) //what variable you wanna test
{
//a bunch of cases
case 1:
cout<<"you are a pirate"<<endl;
break; //you don't need to go through whole of those options
case 2:
cout<<"you are human"<<endl;
break;
default: //if none of those matches, then execute this code
cout<<"I don't know what you are"<<endl;
}
system("pause");
return 0;
return 0;
}
'Computer General > C++ development from the beginning' 카테고리의 다른 글
File Input/Output (0) | 2014.12.16 |
---|---|
Structures (0) | 2014.12.16 |
Logical OR operator (0) | 2014.12.16 |
The if Statement (0) | 2014.12.12 |
Address Operator & Pointer (0) | 2014.12.12 |