编制一个结账系统有累计功能
但输入0时停止输入,显示累积和,并能实现找零功能
代码如下:
代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
double sum = 0; //
double price, pay;
int i = 1;
printf("***************收银软件**************\n");
printf("**************结账请输入0************\n");
while (1)
{
printf("第 %d 笔金额:",i);
scanf("%lf", &price);
if (price == 0)
break;
sum += price;
printf("商品总笔数:%d 当前累计和:%.2f\n", i, sum);
i++;
}
printf("\n\n收到:");
scanf("%lf", &pay);
if (pay > sum)
printf("找零:%.2f 交易成功 欢迎下次光临,谢谢!\n", pay - sum);
else if (pay == sum)
printf("正好,无需找零\n");
else
printf("支付金额不足,请再支付%.2f", sum - pay);
printf("--------------------------------\n");
return 0;
}