
C语言编程,大虾帮忙看一下
商场购物(购物超过2000元,六折;超过1000元,七折;超过500元,八折)。编一个程序,输入消费金额,求应该拿到的折扣.在写一下编写思路....
商场购物(购物超过2000元,六折;超过1000元,七折;超过500元,八折)。编一个程序,输入消费金额,求应该拿到的折扣. 在写一下编写思路.
展开
展开全部
int x,y,z
printf("请输入消费金额");
scanf("%d",x);
if(x>2000) //如果消费金额过2000 就打6折,y的值为打折后的金额
{
y=x*0.6;
}
else if(x>1000&&x<2000)//如果消费金额过1000 就打7折,y的值为打折后的金额
{
y=x*0.7;
}
else
{ if(x>500&&x<1000)//如果消费金额过500 就打8折,y的值为打折后的金额
{
y=x*0.8;
}
else
{
y=x;
}
}
printf("打折后的金额为=%d",y)
应该是这样,好久没摸c了,测试下看看,如果错了再说
printf("请输入消费金额");
scanf("%d",x);
if(x>2000) //如果消费金额过2000 就打6折,y的值为打折后的金额
{
y=x*0.6;
}
else if(x>1000&&x<2000)//如果消费金额过1000 就打7折,y的值为打折后的金额
{
y=x*0.7;
}
else
{ if(x>500&&x<1000)//如果消费金额过500 就打8折,y的值为打折后的金额
{
y=x*0.8;
}
else
{
y=x;
}
}
printf("打折后的金额为=%d",y)
应该是这样,好久没摸c了,测试下看看,如果错了再说
展开全部
不要大虾:
double pay(int sum,int discount)
{return checkSum = sum*discount;}
void main(){
if(sum>2000)
checkSum=pay(sum,0.6);
else if (sum>1000)
checkSum=pay(sum,0.7);
else if(sum>500)
checkSum=pay(sum,0.8);
else
checkSum=pay(sum,1);
cout<<checkSum<<endl;
double pay(int sum,int discount)
{return checkSum = sum*discount;}
void main(){
if(sum>2000)
checkSum=pay(sum,0.6);
else if (sum>1000)
checkSum=pay(sum,0.7);
else if(sum>500)
checkSum=pay(sum,0.8);
else
checkSum=pay(sum,1);
cout<<checkSum<<endl;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
main()
{
float cost;
printf("Please insert the cost:");
scanf("%f", &cost);
if (cost >= 2000)
printf("The price after discount is %.1f", cost*0.6);
else if (cost >= 1000 && cost < 2000)
printf("The price after discount is %.1f", cost*0.7);
else if (cost >= 500 && cost < 1000)
printf("The price after discount is %.1f", cost*0.8);
else
printf("there is no discount!");
}
main()
{
float cost;
printf("Please insert the cost:");
scanf("%f", &cost);
if (cost >= 2000)
printf("The price after discount is %.1f", cost*0.6);
else if (cost >= 1000 && cost < 2000)
printf("The price after discount is %.1f", cost*0.7);
else if (cost >= 500 && cost < 1000)
printf("The price after discount is %.1f", cost*0.8);
else
printf("there is no discount!");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询