Tuesday 7 July 2020

Switch Statement in C++

Switch Statement in C++

Code:
#include<iostream>
using namespace std;
int main()
{
float x;
float y;
int d;
int e;
char opr;
cout<<" Enter 1st Arthimatic operation"<<endl;
cin>>x;
cout<<" Enter 2nd Arthimatic operation"<<endl;
cin>>y;
cout<<" Enter Operator"<<endl;
cin>>opr;

float sum=x+y;
float product=x*y;
float minus=x-y;
float div= x/y;
switch (opr){

case '+' :
cout<< x << " + " <<y<<" is " <<sum<<endl;
break;
case '-':
cout<<x<<" -" <<y<< " is " <<minus<<endl;
break;
case '*':
cout<<x<< " *" <<y<< " is " <<product<<endl;
break;
case '/':
cout<<x<< " /" <<y<< " is " <<div<<endl;
break;
case'%':
cout<<" Modulus of x & y is " <<d%e<<endl;
break;
default:
cout<<" Invalid Arthimatic Operation"<<endl;
}



return 0;

}

No comments:

Post a Comment