用c语言写一个学生个人消费管理系统所需实现功能有消费时间消费金额累计消费金额
以下是一个简单的学生个人消费管理系统的代码示例:
#include <stdio.h>
int main() {
int n; // 消费记录数目
float total = 0; // 累计消费金额
printf("请输入消费记录数目:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int year, month, day; // 消费时间
float amount; // 消费金额
printf("请输入第%d条消费记录的时间和金额(格式为年 月 日 金额):", i);
scanf("%d %d %d %f", &year, &month, &day, &amount);
printf("消费时间:%d年%d月%d日,消费金额:%.2f元\n", year, month, day, amount);
total += amount;
}
printf("累计消费金额:%.2f元\n", total);
return 0;
}
运行程序后,会提示用户输入消费记录数目,然后依次输入每条消费记录的时间和金额。程序会输出每条消费记录的时间和金额,并计算累计消费金额。输出结果示例:
请输入消费记录数目:3
请输入第1条消费记录的时间和金额(格式为年 月 日 金额):2021 10 1 50
消费时间:2021年10月1日,消费金额:50.00元
请输入第2条消费记录的时间和金额(格式为年 月 日 金额):2021 10 3 20
消费时间:2021年10月3日,消费金额:20.00元
请输入第3条消费记录的时间和金额(格式为年 月 日 金额):2021 10 5 80
消费时间:2021年10月5日,消费金额:80.00元
累计消费金额:150.00元
``
原文地址: https://www.cveoy.top/t/topic/fWQI 著作权归作者所有。请勿转载和采集!