Reputation: 3
#include <stdio.h>
int main() {
float a, b, c, d, e, f, x, y;
printf("Insert the 4 coefficients\n");
scanf("%f%f%f%f\n", a, b, d, e);
printf("Insert the 2 constants\n");
scanf("%f%f\n", c, f);
x=(c*e-b*f)/(a*e-b*d);
y=(a*f-c*d)/(a*e-b*d);
if (a*e-b*d!=0)
printf("The system is possible and determined. The results are x=%f and y=%f\n", x, y);
else if (a*e-b*d==0 && a*f-c*d==0 && c*e-b*f==0)
printf("The system is possible and undetermined\n");
else
printf("The system is impossible");
return 0;
}
I have this code in C and whenever I go to compile it i get this:
warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double’ [-Wformat=]
7 | scanf("%f%f%f%f\n", a, b, d, e);
| ~^ ~
| | |
| float * double
This error repeats for all the variables on both the scans. I don't understand what's wrong, please help!
Upvotes: 0
Views: 66
Reputation: 338
scanf function expects a pointer to your variable, not the variable itself. You can easily fix it by passing the address of your variable using the unary & (address-of) operator:
scanf("%f%f%f%f\n", &a, &b, &d, &e);
Note: only string (char str[n]) does not need this address(& sign) in the scanf function.
Upvotes: 1