Tech

How to Create Calculator Using Switch in C++

How to Create Calculator Using Switch in C++: Hello, Everyone today i am going to share with You How to Create Calculator While using Switch in C++.  This C++ Program will take an Arithmetic Operator Such as (+,-,/,*,%) and two Operands From the user and performs the calculation on the two operands depending upon the operator entered by the user.

How to Create Calculator Using Switch in C++

1

2

3

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
char op;
cout<<endl<<“Enter the 1st value=”;cin>>a;
cout<<endl<<“Enter the 2nd value=”;cin>>b;
cout<<endl<<“Enter the Operator (-,+,/,*,%,p,x,a)=”;cin>>op;
switch (op)
{
case ‘+’:
{
c=a+b;
cout<<endl<<c;
break;
}
case ‘-‘:
{
c=a-b;
cout<<endl<<c;
break;
}
case ‘/’:
{
c=a/b;
cout<<endl<<c;
break;
}
case ‘*’:
{
c=a*b;
cout<<endl<<c;
break;
}
case ‘%’:
{
c=a%b;
cout<<endl<<“The Mod is=”<<c;
break;
}
case ‘p’:
{
c=a/b*100;
cout<<endl<<“The Percetage is=”<<c;
break;
}
case ‘x’:
{
c=a*b;
cout<<endl<<“The Squre is=”<<c;
}
case ‘a’:
{
c= (a+b)/2;
cout<<endl<<“The Average is=”<<c;
break;
}
}
getch();
}

Output Display

4

5

6

Related Articles

Leave a Reply

Back to top button