#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
int main()
{
clrscr();
char ch,ch1;
float a,b,add,sub,multi,div;
cout<<"\nsimple calculator:";
cout<<"\n1.Addition";
cout<<"\n2.Subtraction";
cout<<"\n3.Multiplication";
cout<<"\n4.Division";
cout<<"\n5.Exit"<<"\n";
cout<<"Enter your choice:";
do
{
cin>>ch;
if(ch=='1'|| ch=='2'|| ch=='3'|| ch=='4')
{
cout<<"Enter the value of a:";
cin>>a;
cout<<"Enter the value of b:";
cin>>b;
}
switch(ch)
{
case'1':add=a+b;
cout<<"Addition="<<add;
break;
case'2':sub=a-b;
cout<<"Subtraction="<<sub;
break;
case'3':multi=a*b;
cout<<"Multiplication="<<multi;
break;
case'4':if(b==0)
cout<<"Divide by Zero error!!!";
else
div=b/a;
cout<<"Division="<<div;
break;
case'5':cout<<"breaking:";
exit(0);
default:cout<<"Wrong choice!!!";
cout<<"Enter a valid one";
break;
}
cout<<"\nWant to enter more (y/n)?";
cin>>ch1;
if(ch1=='y'|| ch1=='y')
cout<<"again enter your choice (1-5):";
}
while(ch1=='y'|| ch1=='y');
getch();
return(0);
}
#include<conio.h>
#include<math.h>
#include<process.h>
int main()
{
clrscr();
char ch,ch1;
float a,b,add,sub,multi,div;
cout<<"\nsimple calculator:";
cout<<"\n1.Addition";
cout<<"\n2.Subtraction";
cout<<"\n3.Multiplication";
cout<<"\n4.Division";
cout<<"\n5.Exit"<<"\n";
cout<<"Enter your choice:";
do
{
cin>>ch;
if(ch=='1'|| ch=='2'|| ch=='3'|| ch=='4')
{
cout<<"Enter the value of a:";
cin>>a;
cout<<"Enter the value of b:";
cin>>b;
}
switch(ch)
{
case'1':add=a+b;
cout<<"Addition="<<add;
break;
case'2':sub=a-b;
cout<<"Subtraction="<<sub;
break;
case'3':multi=a*b;
cout<<"Multiplication="<<multi;
break;
case'4':if(b==0)
cout<<"Divide by Zero error!!!";
else
div=b/a;
cout<<"Division="<<div;
break;
case'5':cout<<"breaking:";
exit(0);
default:cout<<"Wrong choice!!!";
cout<<"Enter a valid one";
break;
}
cout<<"\nWant to enter more (y/n)?";
cin>>ch1;
if(ch1=='y'|| ch1=='y')
cout<<"again enter your choice (1-5):";
}
while(ch1=='y'|| ch1=='y');
getch();
return(0);
}
No comments:
Post a Comment