省钱有用吗?c语言如何编程折扣?
省钱 56
-
拼唤旅灶多多省钱月卡有用。
拼多多月卡包含的权益有5项,分别是每天领神券、免单特权、免费试用、一折买大牌、月卡精选。值得一提的是,只要用户把拼多多月卡开镇租通之后,便可以领取4张5元无门槛优惠券,以及一些大额满减优惠券。
只要用户在购买商品时,就可以使用优惠券抵扣购买,甚至还会有免单、大牌免费领等和扮活动可以参加。2年前 -
-
#include<stdio.h>姿宏
int main(void)
{
while(1)
{
printf(“\n请输入商品价格,桥世无商品时请输入负数!\n”);
float price = 0;
float sum = 0;
while(1)
{
scanf(“%f”,&price);
if(price < 0) break;
sum += price;
}
if(sum > 1000)
{
printf(“您可以享受折扣,应付的金额为%.2f元。\n”,sum*0.955);
}
else
{
printf(“您的消费还不满足折扣要求敏册肢,应付的金额为%.2f元;您只需再消费%.2f元就可以享受折扣!\n”,sum,1000-sum);
}
}
return 0;
}
4年前 -
-
输入原价
根据打态羡折幅度, 输出实际行森售价
如果根据原价有多个打折幅度,那么就用if else
比较简单的,比档闭亩如固定打8折,那么就是
int main()
{
double r;
scanf("%lf",&r);
r*=0.8;
printf("%lf\n",r);
}7年前 -
1 涉及的C语言知识
(1)输入
(2)加减乘除运算
(3)输出
2 一个小示例
#include<stdio.h>
float get_discount(int x){
float output = 0;
//当输入以0结尾时,不合法,返回0
if (x % 10 == 0)
return output;
//当输入为 85 时,代表85折,输出应为0.85
if (x > 10 && x < 100)
output = x / 100.0;
//当输入为 7 时,代表7折,输出应为0.7
穗漏 if (x < 10 && x >= 1)
output = x / 10.0;
return output;
}
int main(){
仔携 float count;
int discount_str;
念族伏 puts("输入书的金额和打印情况(以空格为分割符,按回车结束):");
puts("(如输入的是20 7则表示20元的书打7折)");
scanf("%f %d", &count, &discount_str);
float discount_f = get_discount(discount_str);
if (discount_f == 0)
puts("输入的打折情况不合法.");
else{
float result = count*discount_f;
printf("打折后的金额为:%.2f\n", result);
}
getchar();
getchar();
return 0;
}3 运行情况
9年前
