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

c語言商場購物折扣率

發布時間: 2022-10-20 05:45:34

1. 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;
}

2. 用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;
}
}

3. 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;
}

4. 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;
}

運行樣例:

5. C語言題:輸入一個購物金額求輸出折扣率與付款金額,如圖

#include<stdio.h>
intmain()
{
inti;floatpay;
scanf("%f",&pay);
if(pay<=0)printf("輸入購物金額有誤!");
else
{
if(pay<200)i=10;
elseif(pay<500)i=9;
elseif(pay<1000)i=8;
elsei=7;
i/10?printf("不打折,"):printf("折扣率:%d折,",i);
printf("實際付款金額:%.2f元",pay*i/10);
}
return0;
}

6. C語言題目,使用SWITCH語句計算折扣率。

#include <stdio.h>
int main()
{
double je,zk;
int x;
printf("那個輸入金額(大於0):");
scanf("%lf",&je);
x=(int)(je/100);
switch(x)
{
case 0:case 1:case 2:zk=je;break;
case 3:case 4:zk=je*0.9;break;
case 5:case 6:case 7:zk=je*0.7;break;
default:zk=je*0.5;
}
printf("折扣率為:%f,實際支付金額:%f\n",zk/je,zk);
return 0;
}

7. 用C語言編寫一個程序,要求輸入購買商品的錢款數,輸出相應的折扣率

你這個題目無法實現的,因為折扣率應該是在知道原價的基礎上的。目前給出條件不足。
這里做個假設:
如果輸入是兩個,折扣前和折扣的,那麼可以計算,比如:
float beforePayment,afterPayment;
float percentage;
scanf("折扣前金額=%f",&beforePayment);
scanf("折扣後金額=%f",&afterPayment);
percentage=afterPayment/beforePayment;
printf("產品折扣率為:%.2f",percentage);//保留兩位小數進行顯示

8. 關於C語言編程時的錯誤

我已經測試了,主要是語法錯誤。在VC++6.0中編譯階段就能得到錯誤信息。要保證代碼正確性,首先代碼格式要良好,這樣才容易找出錯誤。
{a[0].score=a[2].score;j=2;}};這句最後的};是多餘的。
還有一個邏輯問題。學生姓名是字元串類型,最後一句輸出時你卻用%c,顯然應當用%s,並且將a[j].name[20]修改為a[j].name
最後一個建議:最後一句輸出也加上\n

9. c語言規定購物不足50元按原價付款,超過50不足100九折付款,超過100,超過部分按八折付款

#include <stdio.h>
double getCash(){
double m;
printf("input number\n");
scanf("%lf",&m);
return m;
}
//c語言規定購物不足50元按原價付款,超過50不足100九折付款,超過100,超過部分按八折付款?
int main(){
double money=getCash();
if (money>50 &&money<100){
money=money*0.9;
} else if (money>=100){
double more=(money-100)*0.8;
money=more+100;
}
printf("%lf\n",money);
}

10. 求助,簡單的C程序編寫 商場購物,每滿100元減20元,每滿500,再減20,如購物770元,實付

#include<stdio.h>

int main(void)
{
int money;
printf("請輸入購物消費金額.\n");
scanf("%d",&money);
int result=0;
result=money-money/100*20-money/500*20;
printf("實際付款金額為:%d",result);
printf("\n");
return 0;
}

這么簡單的程序看得懂吧,不需要我說明吧