switch statement c++ syntax code example
Example 1: c++ switch case statement
switch (n)
{
case 1:
break;
case 2:
break;
default:
}
Example 2: c++ switch
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 3: switch statement in c++
#include <iostream>
using namespace std;
int main () {
char grade = 'D';
switch(grade) {
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
case 'C' :
cout << "Well done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case 'F' :
cout << "Better try again" << endl;
break;
default :
cout << "Invalid grade" << endl;
}
cout << "Your grade is " << grade << endl;
return 0;
}
Example 4: switch c++
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 5: switch cpp
#include<iostream>
using namespace std;
int main(){
switch(<espressione>){
case <costante x>:
break;
case <costante y>:
break;
case <costante z>:
break;
............
default:
break;
}
}