酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

C 语言实现商店优惠购物款额计算:可反复输入,负值提示重输!

以下是使用 C 语言实现的代码: ```c #include <stdio.h> int main() { float amount, total; printf("请输入购物额: "); scanf("%f", &amount); while (amount >= 0) { if (amount >= 1000) { total = amount * 0.85; } else if (amount >= 500 && amount < 1000) { total = amount * 0.9; } else if (amount >= 200 && amount < 500) { total = amount * 0.95; } else if (amount >= 100 && amount < 200) { total = amount * 0.97; } else if (amount >= 0 && amount < 100) { total = amount; } printf("应收款额为: %.2f\n", total); printf("请输入购物额: "); scanf("%f", &amount); } if (amount < 0) { printf("输入有误,请重新输入!\n"); } return 0; } ``` ######[AI写代码神器 | 288点数解答 | 2024-11-07 11:15:34]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]