用c语言编一个程序,尽量容易懂

模拟超市的前台收款过程。以几种水果为例,设苹果每斤 1.8 元,香蕉每斤 1.9 元,
西瓜每斤 2.2 元。输入水果的编号和重量,打印应付的钱数,再输入顾客付款数,打印出
应找的钱数,设编号 0 表示结帐。
【要求】
1)利用符号常量预先规定各种水果的价格;
2)如果输入的编号合法,则输出“input ** weight”,输入重量后,打印该水果的单
价、重量及金额;如果输入的水果编号不存在,则打印相应的提示信息“no this fruit”,重
新输入;如果输入的编号为 0,则打印“the total price is: **”。
用c语言写一个程序 我不太行

img

这样应该可以
#include<stdio.h>
#include<math.h>
int main()
{
double weight,a,b,c,sum;
int num;
a=b=c=0;
while(1)
{
printf("apple num 1;banana num 2; watermelon num 3;total price 0\n");
scanf("%d",&num);
switch(num)
{
case 0:
sum = a + b + c;
printf("the total price is %.2f\n",sum);
break;
case 1:
printf("please input apple weight\n");
scanf("%lf",&weight);
a=weight1.8;
break;
case 2:
printf("please input banana weight\n");
scanf("%lf",&weight);
b=weight
1.9;
break;
case 3:
printf("please input watermelon weight\n");
scanf("%lf",&weight);
c=weight*2.2;
break;
default:
printf("no this fruit\n");
break;
}
if(num==0)
break;
}
return 0;
}