I'm new to C, and I need to make a mini-calculator program (this is homework, but I'm not looking for an answer, I just understand a little). Basically, one function should look like this:
int add(double d, double dd, double *result);
It will return 0 if there are no errors, and -1 if an error occurred (in the case of addition there would not be many errors, but division, for example, division by 0, would be an error).
The user must enter two numbers in the terminal, these numbers will then be used as parameter values ββin the add method. What I do not understand is the result that initially occurs when the method is called? Is it just zero? And why do I want to return 0 or -1 and not the result? For instance:
double result;
returnValue = add(2.0, 5.0, &result);
Obviously, I get 7 as a result, but how do I print this without returning a result? returnValue is 0, so I know there were no errors, so I need to print the result.
source
share