//导致汽车充电的总费用//
main()
{
float purchaseprice, shipmentcosts, ecowaslevy, importlevy, GCNETlevy, TotalDuty;
printf("Enter the purchase price and shipment cost");
scanf("%f,%f", &purchaseprice, &shipmentcosts);
ecowaslevy = 0.01f, importlevy = 0.25f, GCNETlevy = 0.05f;
//FORMULAS FOR THE LEVY//
ecowaslevy = (purchaseprice + shipmentcosts) * (0.01);
importlevy = (purchaseprice + shipmentcosts) * (0.25);
GCNETlevy = (purchaseprice + shipmentcosts) * (0.05);
//FORMULA FOR TOTAL DUTY//
TotalDuty = (ecowaslevy + importlevy + GCNETlevy)*(3.2);
printf("TOTAL DUTY=GHC.%f", TotalDuty);
system("pause");
}
这些是警告:
1> c:\ users \ david \ documents \ visual studio 2013 \ projects \ total expenses \ total expenses \ tot.c(9):警告C4244:' =' :转换为' double' “浮动”,可能导致数据丢失
1> c:\ users \ david \ documents \ visual studio 2013 \ projects \ total expenses \ total expenses \ tot.c(10):警告C4244:' =' :转换为' double' “浮动”,可能导致数据丢失
1> c:\ users \ david \ documents \ visual studio 2013 \ projects \ total expenses \ total expenses \ tot.c(11):警告C4244:' =' :转换为' double' “浮动”,可能导致数据丢失
答案 0 :(得分:3)
在多行中,您乘以0.01
和0.25
等常量值。这些值是双精度数,乘法结果是double,然后存储在精度较低的浮点变量中。这会给你一个编译器警告。要修复它,您可以将f
文字后缀附加到常量值,例如0.01f
和0.25f
等。
答案 1 :(得分:0)
因为sizeof(double) > sizeof(float)
因此你的精确度会下降。