top of page
 switch sentence 

The switch statement compares the value of the variable with more than one case, and if none of the cases are met, we will move to the default case. We can liken it to an if else statement in this way:
(switch = if) (cases = else if)  ({}=break. break) (default = else)
1- We put {(variable name) switch
2- We put all cases between curly braces: cases
3- When we finish setting the cases, we set the default case:default, which will only work if none of the previous cases are met, then we close the curly braces.

Project: Good morning

#include<iostream>//We start by placing the libraries
using namespace std;//We start by placing the libraries
int main(){//main function
cout<<"Please enter the number that decibe your language"<<endl;
cout<<"1- english"<<endl<<"2 arabic"<<endl<<"3-france"<<endl<<"4-turkey"<< ;endl;
int number;//We declare a variable for numbers
cin>>number;//We have the user choose his language number
switch(number){//We perform a print command on the number
case 1://In the first case No. 1, do the following
cout<<"good morning how are you";
break;//Stop and terminate the state
case 2://In the second case No. 2, do the following
cout<<"Good morning, how are you";
break;//Stop and terminate the state
case 3://In the third case No. 3, do the following
cout<<"Bonjour comment-allez vous";
break;//Stop and terminate the state
case 4://In the fourth case No. 4, do the following
cout<<"Günaydın nasılsın";
break;//Stop and terminate the state
default://If none of the previous conditions are met
cout<<"wrong number dude";}
return 0;
}

image.png
bottom of page