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

c語言運營ifelse打折

發布時間: 2022-08-05 03:57:47

1. c語言if else語句是什麼

c語言if else語句是:if和else是c語言中兩個關鍵的函數,if意思為如果,else意思為否則,主要是用來對條件進行判斷,並根據判斷結果執行不同的語句,if一般在if else語句中充當判斷條件,else是兩個語句的連接詞,從而組成if else語句。

if else語句的編輯方法:首先選擇一個c語言編輯器,定義一個變數height,並且進行賦值,在下邊寫上if條件,然後在把不同結果的意思用else連接起來,最後點擊編輯運行,從而就能看到編輯的結果。

c語言常用的語句有:if語句,else語句,switch語句,goto語句,while語句,do…while語句,for語句,break語句,continue語句等;常用的函數有:putchar函數,getchar函數,printf函數,scanf函數等。

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

敲代碼不容易,望採納。對了臨時寫的有可能會有中文字元,稍微注意下,有問題請追問

3. c語言編程、商場促銷、男的不打折、女的打折、怎麼編

int after_money(int money)
{
if (money < 400)
return money;

else if (money < 800)
return (money*0.95);

else if (money < 1200)
return (money*0.925);
else if (money < 1600)
return (money*0.9);
else if (money < 2000)
return (money*0.88);
else
return (money*0.85);
}

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

5. C語言的折扣計算問題 用代碼來編

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void input(){
double rate=0.045,money;
char s[]="",temp[100];
printf("請輸入產品價格:");
scanf("%lf",&money);
double b = money-(int)money;//提取出小數部分
gcvt(b,7,s); //將小數部分轉換成字元串數組為後面判斷有幾個數字准備的
sprintf(temp,"%lf",b); //將小數部分依次存入字元串數組
int count=0; //存放有幾位小數
int i;
for(i=2;i<=strlen(s);i++){//從2開始,因為下標0存放是字元0,下標1存放的是小數點
count++;
}
if(money<=0){
printf("產品價格必須大於0!\n");
input();
/**如果十分位是0,則字元串長度必須減去4,
如果十分不是0,則字元串長度必須減去1,
因為字元串自動在末尾補0了*/
}else if(((int)temp[2]==48&&count-4!=2)||((int)temp[2]!=48&&count-1!=2)){
printf("產品價格必須是兩位小數!\n");
input();
}else{
if(money<=1000){
printf("您的消費還不滿足折扣要求,應付金額為:%.2f米,您只需再消費%.2f,就可以享受折扣\n",money,(1000.01-money));
}else{
printf("您可以享受折扣,應付的金額為:%.2f米\n",(100-rate)*money);
}
}
}
void main(){
input();
}

6. 求C語言大神編一個程序(分別用switch和if-else結構)某商店推出打折活動,要求購物達到或超過2000元的

doublen=0;
scanf("%lf",&n);
boolr1=n>=2000;
boolr2=n>=1000;
boolr3=n>=500;
switch(r1+r2+r3){
case0:
printf("%.2f",n);
break;
case1:
printf("%.2f",n-50);
break;
case2:
printf("%.2f",n*0.85);
break;
case3:
printf("%.2f",n*0.8);
break;
}
if(r3==0){
printf("%.2f",n);
elseif(r2==0)
printf("%.2f",n-50);
elseif(r1==0)
printf("%.2f",n*0.85);
else
printf("%.2f",n*0.8);
}

7. 買書打折用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 運行情況

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

運行樣例:

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

10. 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的不減,
當然 如果你是做題 的話 請嚴格按照題意