㈠ 用c语言编写一个程序,要求输入购买商品的钱款数,输出相应的折扣率
你这个题目无法实现的,因为折扣率应该是在知道原价的基础上的。目前给出条件不足。
这里做个假设:
如果输入是两个,折扣前和折扣的,那么可以计算,比如:
float beforePayment,afterPayment;
float percentage;
scanf("折扣前金额=%f",&beforePayment);
scanf("折扣后金额=%f",&afterPayment);
percentage=afterPayment/beforePayment;
printf("产品折扣率为:%.2f",percentage);//保留两位小数进行显示
㈡ 用C语言写一个打折程序.如图所示
#include<stdio.h>
intmain()
{
intx;
floaty;
printf("请输入本次消费的金额: ");
scanf("%d",&x);
if(x>=1000)
y=x*0.85;
elseif(500<=x&&x<1000)
y=0.9*x;
elseif(300<=x&&x<500)
y=0.96*x;
elseif(x<300&&x>0)
y=x;
printf("实际花费的金额:%.2f",y);
return0;
}
㈢ C语言:某商店规定按照用户的购物款,给出相应的折扣率。规定为: (1)购物款大于1000元,购物为7折;
#include <stdio.h>
int main(void)
{
float a ;
printf ("The amount cost is: ");
scanf ("%f", &a);
if(a > 1000)
printf ("The amount actually paid by customer is : %.2f", a*0.7);
else if(a > 800)
printf ("The amount actually paid by customer is : %.2f", a*0.8);
else if(a > 500)
printf ("The amount actually paid by customer is : %.2f", a*0.9);
else
printf ("The amount actually paid by customer is : %.2f", a);
return 0;
}
㈣ C语言求 ②某商场给出的购物折扣率如下: 购物金额<100元,不打折; 100元≦购物金额<30
#include <stdio.h>
int main(void)
{ float cost;
float discount,pay;
printf("请输入购物金额:");
scanf("%f",&cost);
if(cost>=0)//购物金额大于等于0
{
if(cost>=0&&cost<100)//购物金额为小于100
discount=1;
else if(cost>=100&&cost<300)//购物金额大于等于100小于300
discount=0.9;
else if(cost>=300&&cost<500)//购物金额大于等于300小于500
discount=0.8;
else //购物金额大于等于500
discount=0.75;
pay=cost*discount;
printf("当购物金额是%.2f,折扣为%.2f,实际付款%.2f\n",cost,discount,pay);
/**************************switch语句实现****************************************/
printf("使用switch语句:\n");
int num=cost/100;//对cost/100取整(例如cost=150,num=1)确定所在的区间范围
switch(num){
case 0: discount=1;break;//购物金额为小于100
case 1: discount=0.9;break;
case 2: discount=0.9;break;//case 1,2为购物金额大于等于100小于300
case 3: discount=0.8;break;
case 4: discount=0.8;break;//case 3,4为购物金额大于等于300小于500
default: //购物金额大于等于00
discount=0.75;break;}
pay=cost*discount;
printf("当购物金额是%.2f,折扣为%.2f,实际付款%.2f\n",cost,discount,pay);}
else //购物金额小于0
printf("输入有误,cost必须满足大于等于0");
return 0;
}
㈤ 用c语言 if结构来回答.普通顾客购物满100元 享受9折优惠。会员购物满200
先分析
如果是普通客户:
那么当购物的价格满100元则打折9折;最后的付款将是购物价的90%;
如果是会员:
那么当购物价格满200元则打折7.5,不满的打折8,所以最终付款需要根据购物价来打折。
代码判断如下:
intsalePrice=N;//购物的价格
floatpayPrice;//最后的付款金额
boolisVIP=true/false;//是否是会员
if(isVIP)
{
if(salePrice>=100)
{
payPrice=salePrice*0.9;
}
else
{
payPrice=salePrice;
}
}
else
{
if(salePrice>200)
{
payPrice=salePrice*0.75;
}
else
{
payPrice=salePrice*0.8;
}
}
㈥ 用c语言编写一个衣服打折的程序,一件打九折,两件七点五折,三件或三件以上五折,有会的的神吗,求指导
#include<stdio.h>
intmain()
{
intx;
floatprice,money;
printf("请输入购买件数:");
scanf("%d",&x);
printf("请输入单价:");
scanf("%f",&price);
if(x==1)
money=0.9*price;
elseif(x==2)
money=0.75*2*price;
elseif(x>=3)
money=0.5*x*price;
printf("打折后总金额是:%f",money);
return0;
}
敲代码不容易,望采纳。对了临时写的有可能会有中文字符,稍微注意下,有问题请追问
㈦ c语言一道编程题!会的帮忙 谢谢
#include <stdio.h>
main(){
float price;
int flag=1;
while(flag){
printf("请输入消费金额");
scanf(price,%f);
if(price<0)
{printf("对不起,您输入的数据有误,请重新输入 /n");
continue;}
else if(price<100)
{printf("折扣率是0%/n");
printf("您的应付金额为" & price,%f);
break;
}
else if(price<200)
{printf("折扣率是5%/n");
printf("您的应付金额为" & price*0.95,%f);
break;}
else if(price<500)
{printf("折扣率是10%/n");
printf("您的应付金额为" & price*0.90,%f);
break;}
else if(price<1000)
{printf("折扣率是15%/n");
printf("您的应付金额为" & price*0.85,%f);
break;}
else if(price>=1000)
{printf("折扣率是20%/n");
printf("您的应付金额为" & price*0.80,%f);
break;}
else
break;
}
}
㈧ 高手们请帮我看看如何用switch语句编好下面一题的c语言编程题!
#include <stdio.h>
void main()
{
int a;
float p,d,f;
scanf("%f",&p);
a=p/100;
switch(a){
case 0 : printf("%f",p);break;
case 1 : printf("f=%f,p=%f,d=%f",p-p*(5.0/100.0),p,p*(5.0/100.0));break;
...
...
default :printf ("qing zai shu ru\n");
}
里面的语句块我就不再写了反正都一样~你应该会写对吧~
㈨ c语言入门折扣编程
#include<stdio.h>
int main(void)
{
while(1)
{
printf(" 请输入商品价格,无商品时请输入负数! ");
float price = 0;
float sum = 0;
while(1)
{
scanf("%f",&price);
if(price < 0) break;
sum += price;
}
if(sum > 1000)
{
printf("您可以享受折扣,应付的金额为%.2f元。 ",sum*0.955);
}
else
{
printf("您的消费还不满足折扣要求,应付的金额为%.2f元;您只需再消费%.2f元就可以享受折扣! ",sum,1000-sum);
}
}
return 0;
}
㈩ c语言编写商品打折程序,如图所示,急急急急急
1)
#include"stdio.h"
intmain(intargc,char*argv[]){
doublem,r;
printf("请输入商品的价格: ");
if(scanf("%lf",&m)!=1||m<=0){
printf("输入错误,退出...... ");
return0;
}
printf("请输入折扣率: ");
if(scanf("%lf",&r)!=1||r<=0||r>=1){
printf("输入错误,退出...... ");
return0;
}
printf("商品价格:%.2f元,折扣:%.2f,折扣后份额:%.2f元 ",m,r,m*r);
return0;
}
运行样例: