C przełącznik
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Grotesque Grebe
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
#include <iostream>
using namespace std;
int main(){
int number;
cout<<"Enter an integer: ";
cin>>number;
switch (number){ //switch statement
case 1:
cout<<"NUMBER IS 1"<<endl;
break;
case 2:
cout<<"NUMBER IS 2"<<endl;
break;
case 3:
cout<<"NUMBER IS 3"<<endl;
break;
case 4:
cout<<"NUMBER IS 4"<<endl;
case 5:
cout<<"NUMBER IS 4 OR 5"<<endl;
break;
default:
cout<<"NUMBER IS NOT FROM 1 TO 5"<<endl;
break;
}
cout<<endl;
return 0;
}
//Hope This Works For You!
int x;
cin >> x;
switch(x) {
case 1:
cout << "You Entered 1";
break;
default:
cout << "You Entered " << x;
}
switch(expression) {
case constant-expression :
statement(s);
break; //optional
case constant-expression :
statement(s);
break; //optional
// you can have any number of case statements.
default : //Optional
statement(s);
}