C语言编程,大虾帮忙看一下
发布网友
发布时间:2023-06-22 02:20
我来回答
共3个回答
热心网友
时间:2023-12-27 17:31
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了,测试下看看,如果错了再说
热心网友
时间:2023-12-27 17:31
不要大虾:
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;
热心网友
时间:2023-12-27 17:32
#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!");
}