Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

Calculator implementation using switch


#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
char ch,ch1;
clrscr();
float a,b,c;
do
{
cout<<"Enter \n + for addition \n - for subtraction \n * for multiplication \n / for division \n 5 for exit \n";
cin>>ch;
switch(ch)
{
case'+':
cout<<"Enter first no. = ";
cin>>a;
cout<<"Enter second no. = ";
cin>>b;
c=a+b;                                                                  
cout<<"Addition = "<<c;
break;
case'-':
cout<<"Enter first no. = ";
cin>>a;
cout<<"Enter second no. = ";
cin>>b;
c=a-b;
cout<<"subtraction = "<<c;
break;
case'*':
cout<<"Enter first no. = ";
cin>>a;
cout<<"Enter second no. = ";
cin>>b;
c=a*b;
cout<<"Multiplication = "<<c;
break;
case'/':
cout<<"Enter first no. = ";
cin>>a;
cout<<"Enter second no. = ";
cin>>b;
c=a/b;
cout<<"Division = "<<c;
break;
case'5':
exit(0);
break;
default:
cout<<"Wrong choice !!!";
break;
}
cout<<"\n Do yo want to continue...y or n ";
cin>>ch1;
}
while(ch1=='y'||ch1=='Y');
return 0;
}

 Output


Previous
Next Post »