C++ program to perform arithmetic operations. (basic calculator)

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main(){
float a,b,ans;
int ch;
while(1){
clrscr();
cout<<"1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n 5.Exit\n Enter Your choice"<<endl;
cin>>ch;
cout<<"Enter Two Numer"<<endl;
cin>>a>>b;
switch(ch){
case 1:
ans=a+b;
cout<<"Addition = "<<ans<<endl; break;
case 2:
ans=a-b;
cout<<"Subtraction = "<<ans<<endl; break;
case 3:
ans=a*b;
cout<<"Multiplication = "<<ans<<endl; break;
case 4:
if(b!=0){
ans=a/b;
cout<<"Division = "<<ans<<endl; break;
}
else{
cout<<"Value of divisor b will not '0' \n Try Again!!"<<endl;
}
break;
case 5: exit(0);
default :
cout<<"Worng Choice"<<endl;
}
getch();
}
}

No comments:

Post a Comment