Okay so I made this program to help me out with my homework and because I wanted to improve my C expertise. Everything compiles fine when I do "gcc file.c -lm", but when I run it with a number at the command line as an argument, my program only returns 70.0000.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double temp(double hour){
double t = (3.14/12)*hour;
double c = cos((double)t);
double temp = 13 * c + 57;
return temp;
}
int main ( int argc, char *argv[]){
double temperature = temp((double)atol(argv[0]));
printf("%f\n", temperature);
}
argv[0]
is probably your program name. You want argv[1]
, I expect. Check out this tutorial for a quick and easy explanation.
Besides that, is there a reason you're using atol(3)
and casting to double
rather than just using atof(3)
which returns a double
directly?
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