exercise2.c
来自「北大青鸟软件工程师ppt的学生用书源代码」· C语言 代码 · 共 37 行
C
37 行
#include <stdio.h>
void main ()
{
/*用 ch 存储顾客是否是会员的信息
*用 cost1、cost2 和 cost3 三个单精度浮点型变量存储购买商品的费用 */
char ch;
float cost1, cost2, cost3;
float total_cost;
double discount, pay;
printf("\n 是否是会员?(y/n)");
fflush(stdin);
scanf("%c",&ch);
printf("\n 输入购买第一件商品的费用:");
scanf("%f", &cost1);
printf("\n 输入购买第二件商品的费用:");
scanf("%f", &cost2);
printf("\n 输入购买第三件商品的费用:");
scanf("%f", &cost3);
total_cost = cost1 + cost2 + cost3;
discount = 0;
if((ch=='y') || (total_cost>=100))
{
discount=total_cost*0.1;
}
if((ch=='y') && (total_cost >= 100))
{
discount = total_cost * 0.2;
}
pay = total_cost - discount;
printf("\n 购物总额 = %1.2f 元\n ", total_cost);
printf("\n 折扣金额 = %1.2f 元\n ", discount);
printf("\n 应付总额 = %1.2f 元\n ", pay);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?