请帮我改个程序

来源:百度知道 编辑:UC知道 时间:2024/09/21 05:34:41
#include<stdio.h>
main()
{
int profit;
float sum;
scanf("%d",&profit);
if (profit<=1000)
{
printf("NO");
sum=500;
}
else
{
if(profit>1000&&profit<=2000)
{
printf("10%");
sum=500+profit*10%
}
else
{
if (profit>2000&&profit<=5000)
{
printf("15%");
sum=500+profit*15%
}
else
{
if(profit>5000&&profit<=10000)
{
printf("20%");
sum=500+profit*20%
}
else
{
printf("25%");
sum=500+profit*25%
printf("%d",sum);
}
}
}
}
}
}



是改错吧?没必要打这么多大括号,搞得太复杂了,有几个分号没打,而且最后的else
{
printf("25%");
sum=500+profit*25%
printf("%d",sum);
}
定义的sum是实型,最后输出应该是"%f"
这样写的话有可能就没SUM输出了,如果前面IF成立的话,改为如下:
#include<stdio.h>
main()
{
int profit;
float sum;
scanf("%d",&profit);
if (profit<=1000)
{
printf("NO");
sum=500;
}
else if(profit>1000&&profit<=2000)
{
printf("10%");
sum=500+profit*10%;
}
else if (profit>2000&&profit<=5000)
{
printf("15%");
sum=500+profit*15%;
}
else if(profit>5000&&profit<=10000)
{
printf("20%");
sum=500+profit*20%;
}
else
{
printf("25%");
sum=500+profit*25%;<