I am writing a program that needs to do a bit of arithmetic.
Here’s what I have so far:
#include <stdio.h>
int main(void){
double h, x, n;
printf("enter h > ");
scanf("%1f", &h);
printf("enter x > ");
scanf("%1f", &x);
/* here's where I believe I'm encountering an error */
n = x/h;
return 0;
}
so let’s say I put in h = 0.01 with x = 0.25, I should get n = 0.25/0.01 = 25 right?
I’ve tried typecasting:
n = (float)x/(float)h;
but it doesn’t work…
The problem is probably due to scanf.
I suggest using fgets instead.
But try: