I’m not sure what I’m doing wrong, but I’m not able to read a double from the console. Reading an it works fine for some reason. I’m using Xcode.
double n1;
// get input from the user
printf("Enter first number: ");
scanf("%f", &n1);
printf("%f", n1);
This will always print 0 no matter what I enter.
%fis looking for a float, not a double. If you want to use a double, use the format%lf.As a somewhat interesting aside, clang warns about this without any extra flags, gcc 4.6 won’t warn about it even with
-Wall -Wextra -pedantic.