Ⅰ 用c語言編一個計算衣服價格的程序,要求一件衣服打九折,兩件衣服7.8折,三件打五折,大於三件還是打
#include<stdio.h>
void calc(double prirce,int num){
double total;
if(num==1){
total = prirce*0.9;
}else if(num==2){
total = num*prirce*0.78;
}else{
total=num*prirce*0.5;
}
printf("你買了%d件衣服,衣服的總價格是%2f",num,total);
}
void main(){
double inputPrice[3]={41.56,782.4,87.93};
calc(inputPrice[0],2);
calc(inputPrice[1],3);
calc(inputPrice[2],1);
}
Ⅱ C語言問題求大神請教 某商店推出打折活動,要求購物達到或超過2000元得打八折,購物達到或超過5
int ShoudPay(int value)
{
if(value < 500)
return value;
else if(value >=500 && value < 2000)
return value - 50;
else
return (int )(value * 0.8f);
}
原文沒有提到 1000 - 2000,不科學。不可能500 - 1000的都減價,1000 - 2000的不減,
當然 如果你是做題 的話 請嚴格按照題意
Ⅲ 用C語言寫一個打折程序.如圖所示
#include "stdio.h"
int main()
{ double a,b; //a 表示花的錢數,b表示打折後的錢數
scanf("%lf",&a);//輸入你要花的錢數
if(a>=1000) b=0.85*a;
else
if(a>=500&&a<1000) b=0.9*a;
else
if(a>=300&&a<500) b=0.95*a;
else b=a;
printf("輸出實際花的錢數%lf",b);
}
Ⅳ 用C語言編寫一個程序,要求輸入購買商品的錢款數,輸出相應的折扣率
你這個題目無法實現的,因為折扣率應該是在知道原價的基礎上的。目前給出條件不足。
這里做個假設:
如果輸入是兩個,折扣前和折扣的,那麼可以計算,比如:
float beforePayment,afterPayment;
float percentage;
scanf("折扣前金額=%f",&beforePayment);
scanf("折扣後金額=%f",&afterPayment);
percentage=afterPayment/beforePayment;
printf("產品折扣率為:%.2f",percentage);//保留兩位小數進行顯示
Ⅳ c語言 輸入在一行中給出商品的原價和折扣,在一行中輸出商品的折扣價,保留小數點後 2 位
代碼的錯誤在於,你的代碼中scanf函數那一行,表述第一個參數yj的格式字元串少打了一個%,正確的代碼應該是:scanf(「%d %d」,&yj,&zk);
Ⅵ 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語言編寫一個衣服打折的程序,一件打九折,兩件七點五折,三件或三件以上五折,有會的的神嗎,求指導
#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語言 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語言怎麼編程
1 涉及的C語言知識
(1)輸入
(2)加減乘除運算
(3)輸出
2 一個小示例
#include<stdio.h>
floatget_discount(intx){
floatoutput=0;
//當輸入以0結尾時,不合法,返回0
if(x%10==0)
returnoutput;
//當輸入為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;
returnoutput;
}
intmain(){
floatcount;
intdiscount_str;
puts("輸入書的金額和列印情況(以空格為分割符,按回車結束):");
puts("(如輸入的是207則表示20元的書打7折)");
scanf("%f%d",&count,&discount_str);
floatdiscount_f=get_discount(discount_str);
if(discount_f==0)
puts("輸入的打折情況不合法.");
else{
floatresult=count*discount_f;
printf("打折後的金額為:%.2f ",result);
}
getchar();
getchar();
return0;
}
3 運行情況
Ⅹ 用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;
}