Kindly convert the structure of the program from "if else if" statement to "switch" statement. /* Make a C++ program that will ask the user to select a specific arithmetic operation based on the options that will be shown in the program. Then, once the user will select an operation, the program will ask the user to input two positive values. The program will immediately output the result of the selected operation.*/ #include using namespace std; int main(){ cout<< "roselyn centinales"; int select; float a, b, sum=0, diff=0, prod=0, quo=0, mod=0; BalikDiri: cout<<"MENU:"<>select; //if(condition)else if(condition) //nested if if(select==1) { diri1: cout<<" \n***ADDITION***"<>a>>b; if(a>=0 && b>=0){ sum=a+b; cout<<"The sum is "<< sum <>a>>b; if(a>=0 && b>=0){ diff=a-b; cout<<"The difference is "<< diff<>a>>b; if(a>=0 && b>=0){ prod=a*b; cout<<"The product is "<< prod<>a>>b; if(a>=0 && b>=0){ quo=a/b; cout<<"The quotient is "<< prod<>a>>b; int x=a, y=b; if(x>=0 && y>=0){ mod=x%y; cout<<"The Modulud is "<< mod<
Kindly convert the structure of the program from "if else if" statement to "switch" statement.
/* Make a C++ program that will ask the user to select a specific arithmetic operation
based on the options that will be shown in the program. Then, once the user will select
an operation, the program will ask the user to input two positive values. The program
will immediately output the result of the selected operation.*/
#include<iostream>
using namespace std;
int main(){
cout<< "roselyn centinales";
int select;
float a, b, sum=0, diff=0, prod=0, quo=0, mod=0;
BalikDiri:
cout<<"MENU:"<<endl;
cout<<"[1] Addition\n";
cout<<"[2] Subtraction\n";
cout<<"[3] Multiplication\n";
cout<<"[4] Division\n";
cout<<"[5] Modulus\n";
cout<<"[6] Exit\n";
cout<<"Kindly press the number that corresponds to the operation of your choice."<<endl;
cout<<"You've selected: ";
cin>>select;
//if(condition)else if(condition)
//nested if
if(select==1)
{
diri1:
cout<<" \n***ADDITION***"<<endl;
cout<<"Input two positive values:"<<endl;
cin>>a>>b;
if(a>=0 && b>=0){
sum=a+b;
cout<<"The sum is "<< sum <<endl;
system("pause");
goto BalikDiri;
}else{
cout<<"Invalid input. Please enter positive values!!!!!";
system("pause");
system("cls");
goto diri1;
}
}else if(select==2){
forInvalidInput:
cout<<"\n***SUBTRACTION***"<<endl;
cout<<"Input two positive values:"<<endl;
cin>>a>>b;
if(a>=0 && b>=0){
diff=a-b;
cout<<"The difference is "<< diff<<endl;
system("pause");
system("cls");
goto BalikDiri;
}else{
cout<<"Invalid input. Please enter positive values!!!!!";
system("pause");
system("cls");
goto forInvalidInput;
}
}else if(select==3){
diri2:
cout<<"\n***MULTIPLICATION***"<<endl;
cout<<"Input two positive values:"<<endl;
cin>>a>>b;
if(a>=0 && b>=0){
prod=a*b;
cout<<"The product is "<< prod<<endl;
system("pause");
system("cls");
goto BalikDiri;
}else{
cout<<"Invalid input. Please enter positive values!!!!!";
system("pause");
system("cls");
goto diri2;
}
} else if(select==4){
diri3:
cout<<"\n***DIVISION***"<<endl;
cout<<"Input two positive values:"<<endl;
cin>>a>>b;
if(a>=0 && b>=0){
quo=a/b;
cout<<"The quotient is "<< prod<<endl;
system("pause");
system("cls");
goto BalikDiri;
}else{
cout<<"Invalid input. Please enter positive values!!!!!";
system("pause");
system("cls");
goto diri3;
}
}else if(select==5){
diri4:
cout<<"\n***MODULUS***"<<endl;
cout<<"Input two positive values:"<<endl;
cin>>a>>b;
int x=a, y=b;
if(x>=0 && y>=0){
mod=x%y;
cout<<"The Modulud is "<< mod<<endl;
system("pause");
system("cls");
goto BalikDiri;
}else{
cout<<"Invalid input. Please enter positive values!!!!!";
system("pause");
system("cls");
goto diri4;
}
}else if(select==6){
cout<<"****THANK YOU!****";
exit(0);
}else{
cout<<"**Invalid input. Please enter values from 1-6!!!!!**"<<endl;
system("pause");
system("cls");
goto BalikDiri;
}
return 0;
}
Step by step
Solved in 2 steps