I tried to make a program that has a correct Divide function. My code was:
#include <iostream>
using namespace std;
double x,y,z,a;
double divide(x,y) {
if (x >= y) {
x=z;
z=y;
y=x;
return(x/y);
}
else
return(y/x);
}
int main()
{
double x,y,z ;
cout << "Enter x " <<endl;
cin >> x;
cout << "Enter y " <<endl;
cin >> y;
a = divide (x,y);
cout << a <<endl;
system("pause");
return 0;
}
And I have 2 errors:
expected `,' or `;' before '{' token
on the {
line. Right under the double divide (x, y)
line
And another error
divide cannot be used as a function
on the a = divide (x, y);
line.
I am using Code: Blocks
You need to specify a proper function signature for the function divide
. Specifically, the arguments to the function are missing their types:
double divide(double x, double y)
{
...
}
You also need to create a scope for each block in an if statement:
if (x > y)
{
...
}
else
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With