rewrite the following code using if else if statement.
switch(direction)
{
case "N" : a = "North"; break;
case "E" : a = "East"; break;
case "W" : a = "West"; break;
case "S" : a = "South"; break;
default : a = "Enter correct code";
}
document.write (a)
Answers
int main(){
char direction;
cout<<"enter the direction"<<endl;
cin>>direction;
if(direction=='n' || direction=='N'){
cout<<"North"<<endl;
} else
if(direction=='e' || direction=='E'){
cout<<"East"<<endl;
}else
if(direction=='w' || direction=='W'){
cout<<"West"<<endl;
}else
if(direction=='s' || direction=='S'){
cout<<"South"<<endl;
}else{
cout<<"Enter correct code"<<endl;
}
return 0;
}
Answer:int main(){
char direction;
cout<<"enter the direction"<<endl;
cin>>direction;
if(direction=='n' || direction=='N'){
cout<<"North"<<endl;
} else
if(direction=='e' || direction=='E'){
cout<<"East"<<endl;
}else
if(direction=='w' || direction=='W'){
cout<<"West"<<endl;
}else
if(direction=='s' || direction=='S'){
cout<<"South"<<endl;
}else{
cout<<"Enter correct code"<<endl;
}
return 0;
}
Read more on Brainly.in - https://brainly.in/question/7336308#readmore