R
Richard
Bill Cunningham said:Other than the fact that your formula 'price-ma*ma/100' must be wrong, not
really (if we don't count the incorrect printf specifier, the allergy to
white space, and the failure to have a useful error message). Run the
following version of your code and see what happens:
#include <stdio.h>
#include <stdlib.h>
double os(double price, double ma)
{
/* mha: note that ma / ma * 100 == 100 always */
printf("sanity check on the value computed:\n"
"price = %g, ma = %g\n"
"ma / ma * 100 = %g\n"
"price - ma / ma * 100 = %g\n",
price, ma, ma / ma * 100, price - ma / ma * 100);
return price - ma / ma * 100;
}
int main(int argc, char *argv[])
{
double price, ma; /* mha: moved to beginning of block for
pre-C99 compilers */
if (argc != 3) {
fprintf(stderr, "usage error: "
"price and 'ma' arguments needed\n");
exit(EXIT_FAILURE);
}
price = strtod(argv[1], NULL);
ma = strtod(argv[2], NULL);
printf("added sanity check on input:\n"
" price = %.2f, ma = %.2f\n", price, ma);
printf("%.2f\n", os(price, ma)); /* mha: was "%f.2" */
return 0;
}
I don't quite know what you're doing here but it does look interesting.
Bill
If you do not know what he is doing, how can it be interesting? Did you
compare your code and his? Can you give any idea what you think the
differences might be?