Aim :- Write a C++ Program to Make a Simple Menu-Driven Calculator to Add, Subtract, Multiply or Divide.
This program takes an arithmetic operator (+, -, *, /) and two operands from an user and performs the operation on those two operands depending upon the operator entered by user.
This Calculator is made by using switch case operation.
C++ Program Code :
#include <conio.h>
#include <iostream.h>
void main()
{
int a,b,ans,ch,n=0;
char y;
clrscr();
cout<<"1.Addition\t2.Substraction\t3.Multiplication\t4.Division\t5.Exit\n";
do
{
cout<<"Enter your choice : ";
cin>>ch;
cout<<"Enter value of a & b : \n ";
cin>>a>>b;
switch(ch)
{
case 1 : ans=a+b;
cout<<"Addition : "<<ans;
break;
case 2 : ans=a-b;
cout<<"Substraction : "<<ans;
break;
case 3 : ans=a*b;
cout<<"Multiplication : "<<ans;
break;
case 4 : ans=a/b;
cout<<"Division : "<<ans;
break;
default : exit(0);
break;
}
cout<<"\nWant To Continue y/n ";
cin>>y;
}while(ch>>0&&4);
getch();
}
Output :
0 Comments