该程序计算折扣。如果我将变量 priceperitem 更改为 int 并在代码中进行必要的更改(格式说明符等),计算折扣的语句给了我完全不同的答案。谁能解释这背后的逻辑。我已经努力但不能明白怎么了??..它可能与运算符的关联性有关..还是只是除法的事情......???
#include<stdio.h>
main()
{
int quantity;
float priceperitem,expense,discount;
printf("Price Per Item =");
scanf("%f",&priceperitem);
printf("How much quantity do you want =");
scanf("%d",&quantity);
if(quantity>1000)
{
discount=quantity*priceperitem*10/100;
printf("The discount is %f\n",discount);
expense=quantity*priceperitem - discount;
printf("The discounted price is %f",expense);
}
}