我在使用float时遇到了一些麻烦,因为每当我输入十进制数字时,程序就结束了。当我不输入整数时,它可以很好地工作(我的编译器是代码块)
这是代码
#include <stdio.h>
int main()
{
float kmm; /* Monthly traveled Kilometers */
float costo; /* Cost for a liter of gas*/
float kmp; /* Traveled Kilometers with a liter of gas*/
float ln; /* Needed liters monthly */
float costot; /* Monthly total cost*/
float costom; /*Average daily cost*/
printf("Enter traveled monthly Kms\n");
scanf("%f", &kmm);
printf("Enter cost for a liter of gas\n");
scanf("%f", &costo);
printf("Enter traveled Kms with a single liter\n");
scanf("%f", &kmp);
ln=kmm/kmp; /* Needed liters monthly */
costot=ln*costo;
printf("La spesa mensile totale è %.3f\n", costot);
costom=costot/30;
printf("Il costo medio giornaliero è %.3f\n", costom);
return 0;
}
你能解释出什么问题了吗?
更新:我用英语编辑。