當前位置:首頁 » 編程語言 » c語言消費越大折扣越大
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言消費越大折扣越大

發布時間: 2022-07-29 18:50:54

㈠ 用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;
}

運行樣例: