我想写一个代码,根据洗衣的重量计算洗衣费。我希望它停止后,4输入,并计算总销售额为当天。我似乎无法正确地打印输出,它继续打印所有输出的0。
#include<stdio.h>
int main()
{
printf("\t\tWELCOME TO UNIMAP LAUNDRY");
printf("\nThis program is to display laundry price paid by customers\n");
float l, W, sum, r;
for (l = 0; l < 4; l++) {
printf("Please enter laundry weight(kg):");
scanf("%f", & W);
printf("Total amount to pay is RM%f\n", r);
if (W < 1)
r == (W * 1.2);
else if (W < 7)
r == (W * 0.9);
else if (W < 12)
r == (W * 0.6);
else
r == (W * 0.7);
}
sum += r;
printf("The total sales are RM%f", sum);
return 0;
}我得到的输出示例:
WELCOME TO UNIMAP LAUNDRY
This program is to display laundry prices paid by customers
Please enter laundry weight(kg):12
The total amount to pay is RM0.000000
Please enter laundry weight(kg):6
The total amount to pay is RM0.000000
Please enter laundry weight(kg):5
The total amount to pay is RM0.000000
Please enter laundry weight(kg):9
The total amount to pay is RM0.000000
The total sales are RM-29726079709203136512.000000发布于 2022-09-27 12:30:00
==是布尔运算符,=是赋值。
所以而不是
r == (W * 1.2);
写
r = (W * 1.2);
https://stackoverflow.com/questions/73867578
复制相似问题