孵化002 - 今天我们来卖鸡蛋

来源:互联网 发布:mac系统字体下载 编辑:程序博客网 时间:2024/04/27 17:59

店家有100个鸡蛋,10个以下每个1元,10个及以上每个0.8元。
通过编写程序,根据顾客购买的数量自动算出顾客应付款,并输出店家还剩下多少个

例如:
输入:20
输出:应付16.0元,剩下80个鸡蛋

#include <stdio.h>#define Less10_Price 1#define More10_Price 0.8int main(int argc, const char * argv[]) {    int buyEgges;    float price = 0.0;    int eggesNum = 100;    //这里有循环输入输出,可采用do-while循环  或者  while 循环    do{        printf("请输入鸡蛋个数:\n");        scanf("%d",&buyEgges);        //首先判断总共的鸡蛋个数是否大于100个        if (buyEgges <= eggesNum) {            //这里判断买的个数是否大于10            if (buyEgges >=10) {                price = buyEgges * More10_Price;            }else{                price = buyEgges * Less10_Price;            }            //剩下的个数等于总数减去卖掉的            eggesNum -= buyEgges;            printf("应付%f元,剩下%d个鸡蛋\n",price,eggesNum);        }else{            printf("请核对鸡蛋个数,现在鸡蛋剩下%d个\n",eggesNum);        }    }while (eggesNum > 0);    return 0;}

今天我们的鸡蛋先卖到这里!以后看群公告,解答的练习题都在博客里面!

1 0
原创粉丝点击