Can someone help me with this code. I don't understand the error in this code. Thanks in advance. :)
#include<iostream.h>
#include<conio.h>
using namespace std;
int add(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int y);
int main(){
int x,y;
cout<<"Enter 1st Number: "<<endl;
cin>>x;
cout<<"Enter 2nd Number: "<<endl;
cin>>y;
execute(x,y);
getch();
return 0;
}
int add(int x, int y){
int sum;
sum=x+y;
return (sum);
}
int subtract(int x, int y){
int diff;
diff=x-y;
return (diff);
}
int multiply(int x, int y){
int prod;
prod=x*y;
return (prod);
}
int divide(int x, int y){
int quotient;
quotient=x/y;
return (quotient);
}
int result(int r){
cout<<"Result: "<<r;
}
int execute(int b, int c){
char select;
int a, s, m, d;
system("cls");
cout<<"Menu"<<endl;
cout<<"[A]ddtion"<<endl;
cout<<"[S]ubtraction"<<endl;
cout<<"[M]ultiplication"<<endl;
cout<<"[D]ivision"<<endl;
cout<<"Select: ";
cin>>select;
switch(select){
case 'a':
a=add(x,y);
result (a);
break;
case 's':
s=subtract(x,y);
result (s);
break;
case 'm':
m=multiply(x,y);
result (m);
break;
case 'd':
d=divide(x,y);
result (d);
break;
default:
cout<<"Please Check Your Answer";
}
return 0;
}
You can use the ?: operator for simple if then else constructs - have a look in the tutorial page at the top left of this page.
number < PRECISION ? true : false;
Also, can you please use code tags? Select your code then press the <> button on the formatting menu. Your code should look like the code posted by me & others.