0
点赞
收藏
分享

微信扫一扫

(每日一练c语言)商品优惠计算器

伢赞 2022-02-04 阅读 100

商品优惠计算器

商品优惠计算器 使用if语句编程实现输入购货金额,输出实际付款金额。购货折扣率如下:
购货金额≤500元 不打折
500元<购货金额≤1000元 9折
1000元<购货金额 8折

以下程序实现了这一功能:

#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
    float money = 0.0;
    float pay = 0.0;
    bool run = true;
    while (run)
    {
        printf("\n请输入购货金额:\n");
        scanf("%f", &money);
        if (money > 1000)
        {
        	pay = money * 0.8;
        	printf("打八折,应付金额:%.2f\n", pay);
        }
        else if ((money > 500) && (money <= 1000))
        {
	        pay = money * 0.9;
	        printf("打九折,应付金额:%.2f\n", pay);
        }
        else if (money <= 500)
        {
	        printf("不打折,应付金额:%.2f\n", money);
        }
    }
    return 0;
}
举报

相关推荐

c语言每日一练(9)

c语言每日一练(12)

c语言每日一练(13)

C语言每日一练(1)

c语言每日一练(15)

c语言每日一练(3)

0 条评论