You are on page 1of 2

The final program is given below:

#include<iostream.h>
#include<conio.h>
int add(int a, int b)
{
int r=a+b;
return r;
}
int sub (int a, int b)
{
int r=a-b;
return r;
}
int mul (int a, int b)
{
int r=a*b;
return r;
}
int div (int a, int b)
{
int r=a/b;
return r;
}
void main ()
{
clrscr();
int n1, n2, result;
char op;
cout<<calculator for 5 calculations : \n;
for(int j=0;j<5;j++)
{
cout<< \n Enter 1st number : ;
cin>>n1;
cout<< \n Enter 2nd number : ;
cin>>n2;
cout<< \n Enter the operator +, -, *, / or E to Exit : ;
cin>>op;
if (op == +)
{

result=add(n1,n2);
cout<< \n Addition is = <<result<<\n;
}
else if (op == -)
{
result=sub (n1,n2);
cout<< \n Subtraction is = <<result<<\n;
}
else if (op == *)
{
result=mul (n1,n2);
cout<< \n Multiplication is = <<result<<\n;
}
else if (op == /)
{
result=div(n1,n2);
cout<< \n Division is = <<result<<\n;
}
else if ((op == e) || (op == E))
{
cout<< \n Thank you ;
break; /*To end the loop*/
}
else
{
cout<<\n Invalid input;
break;
}
}
getch();
}

You might also like