I am completely lost with in terms of how a global variable can return an error code with a global const int. So I wrote one function that basically acquires the appropriate number of numbers for a given formula. I am able to invoke it in my int main function and it runs whenever I run it in cloud9. The problem arises when I submit it because it expects me to flag the error for the function with the given variable.
The instructions are:
returns the integer representing the state of the calculation using global constants for DIVISOR and DIVIDE_ZERO
// the global variable that I am supposed to be using for this function
constint DIVISOR = 0;
constint DIVIDE_ZERO = 1;
// my code for the division function
int division(double a, double b, double &result){
double answer;
answer = (a/b);
cout << "Equation: " << a << "/" << b << endl;
if ((b - 0) <= .000001 ){
cout << "Error: cannot divide by zero." << endl;
}
else{
cout << setprecision(6);
cout << fixed;
cout << "Result: " << answer << endl;
}
return answer;
}
I really just need help with how to return the error with the global variable.