0% found this document useful (0 votes)
7 views2 pages

Switch

Uploaded by

sharmaaman2614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Switch

Uploaded by

sharmaaman2614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ : Program to perform simple arithmetic operations ( +,-,*,/) using

SWITCH

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c=0;
char op;
clrscr();
cout<<"Enter values of a and b:\n";
cin>>a>>b;
cout<<"Enter the choice of operator (+,-,*,/)\n";
cout<<"Press '+' for addition."<<endl;
cout<<"Press '-' for subtraction."<<endl;
cout<<"Press '*' for multiplication."<<endl;
cout<<"Press '/' for division."<<endl;
cin>>op;
switch(op)
{
case '+':
c=a+b;
cout<<"The result is="<<c;
break;
case '-':
c=a-b;
cout<<"The result is="<<c;
break;
case '*':
c=a*b;
cout<<"The result is="<<c;
break;
case '/':
if(b==0)
{
cout<<"Number is not divisible by zero";
break;
}
else
{
c=a/b;
cout<<"The result is="<<c;
break;
}
default:
cout<<"\Invalid Operator.";
break;
}
getch();
}

Enter values of a and b:


70
Enter the choice of operator (+,-,*,/)
Press '+' for addition.
Press '-' for subtraction.
Press '*' for multiplication.
Press '/' for division.
/
Number is not divisible by zero

You might also like