Home / Tech / How to Create Calculator Using Switch in C++
How to Create Calculator Using Switch in C++

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

About Jahanzaib Khan

A Passionate Bloggers from Pakistan, Who Loves to Put Content That Talks About The Reality of Current Situations.

Check Also

Facebook is Now Closer into Building Your Virtual Copy

Facebook is Now Closer into Building Your Virtual Copy

Whenever, it comes to social media platforms to represent yourself, it’s actually who you portray …

Leave a Reply

Your email address will not be published. Required fields are marked *