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

WhatsApp Gold Is Going To Steal All Your Mobile Data-min

WhatsApp Gold is going to steal all your mobile data

Users of WhatsApp have been reported receiving messages in which users are urged to sign …

Leave a Reply

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