c语言 如何用switch语句编写一个有关商场购物金额优惠的选择程式以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
c语言 如何用switch语句编写一个有关商场购物金额优惠的选择程式
#include
int main(int argc, char** argv)
{
int amount = 0;
scanf("%d", &amount);输入顾客购买的总额
int status = amount/1000;
switch (status)
{
case 0: break;
case 1: amount = amount * 0.95; break;
case 2: amount = amount*0.90; break;
case 3: amount *= 0.85; break;
default: amount *= 0.80; break;
}
printf("%d\n", amount);打印出打折后的总额
return 0;
}
编写c语言程式,输入购物款数,计算并输出优惠价。(要求用switch语句编写)
#include
int main()
{
float totalprice=0,level=0; 总的消费额,打折等级标志
scanf("%d",&totalprice);
if(totalprice<=1000) level=1; 一共分为五等,不同等级,对应不同的优惠策略。
else if(totalprice>1000 && totalprice<=2000) level=2;
else if(totalprice>2000 && totalprice<=3000) level=3;
else if(totalprice>3000 && totalprice<=5000) level=4;
else level=5;
switch(level) 一共分为五等,不同等级,对应不同的优惠策略。
{
case 1: printf("%f",totalprice);break;
case 2: printf("%f",totalprice*0.95);break;
case 3: printf("%f",totalprice*0.90);break;
case 4: printf("%f",totalprice*0.85);break;
default: printf("%f",totalprice*0.80);break;
}
return 0;
}
如何用c语言编写一个收款程式?
#include
int main(){
float sum=5.0;
int n; 购买数量
printf("输入要购买的数量:");
scanf("%d",&n); 输入购买数量
if((n>5)&&(n<=10)){ 打九折
sum=sum*n*0.9;
}
if((n>10)&&(n<=20)){
sum=sum*n*0.8;
}
if((n>20)&&(n<=50)){
sum=sum*n*0.7;
}
if((n>50)&&(n<=100)){
sum=sum*n*0.6;
}
if(n>100){
sum=sum*n*0.6;
}
printf("收款:%.1f",sum);
printf("\n");
}
如何用C语言编写一个关程序的程式?
基本思路:
1. 用Process32First+Process32Next列举所有程序。
2. 对列举的程序取程式名,比较是不是要关掉的程式。
3. 如是,呼叫TerminateProcess()结束它。
有的程式一启动就不止一个程序,所以即使关掉一个,也继续列举。