I am there.
I am learning C and I have this code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double buyval, deliveredval, change;
printf("What the buy value? ");
scanf("%lf", &buyval);
do{
printf("What the value delivered? ");
scanf("%lf", &deliveredval);
if (deliveredval < buyval){
printf("Delivered value must be greater then buy value \n\n");
}
} while (deliveredval < buyval);
change = deliveredval - buyval;
printf("Change is %4.2lf", change);
return 0;
}
With this code, the last print is always 0.00, but I change
printf("Change is %4.2lf", change);
to
printf("Change is %4.2f", change);
It works as expected. Why is this? Are doubles not formatted as lf?
source
share