#include<iostream.h>
#include<conio.h>
#include<stdlib.h> //for exit function
#include<dos.h> //for sleep function
double operation(float, float ,char);
void main()
{
clrscr();
float x,y,z;
char op;
cout<<"enter first value ";
cin>>x;
cout<<"enter second value ";
cin>>y;
cout<<"enter operator ";
cin>>op;
z=operation(x,y,op);
cout<<z;
getch();
}
double operation(float a,float b, char op)
{
float c;
switch(op)
{
case '+' : c=a+b;
break;
case '-' : c=a-b;
break;
case '*' : c=a*b;
break;
case '/' : if(b==0)
{
cout<<"wrong values";
sleep(5);
exit(0);
}
else
c=a/b;
break;
case 'q' : exit(0);
default : cout<<"worng operator";
break;
}
return c;
}
#include<conio.h>
#include<stdlib.h> //for exit function
#include<dos.h> //for sleep function
double operation(float, float ,char);
void main()
{
clrscr();
float x,y,z;
char op;
cout<<"enter first value ";
cin>>x;
cout<<"enter second value ";
cin>>y;
cout<<"enter operator ";
cin>>op;
z=operation(x,y,op);
cout<<z;
getch();
}
double operation(float a,float b, char op)
{
float c;
switch(op)
{
case '+' : c=a+b;
break;
case '-' : c=a-b;
break;
case '*' : c=a*b;
break;
case '/' : if(b==0)
{
cout<<"wrong values";
sleep(5);
exit(0);
}
else
c=a/b;
break;
case 'q' : exit(0);
default : cout<<"worng operator";
break;
}
return c;
}