注册 登录
编程论坛 新人交流区

新手编程过程中的一个问题,求教

misschen 发布于 2007-10-30 21:18, 417 次点击
main()
{float salory=500;
long profit;
printf("input profit\n");
scanf("%1d",&profit);
if(profit<=1000) {salory+=salory;}
if((profit>1000)&&(profit<=2000)) {salory+=profit*0.1;}
if((profit<2000)&&(profit<=5000)) {salory+=profit*0.15;}
if((profit<5000)&&(profit<=10000)) {salory+=profit*0.20;}
if(profit>10000) {salory+=profit*0.25;}
printf("salary=%f\n",salory);
}
 员工底薪为500,利润<=1000,没有提成,1000<利润<=2000提成10%,2000<利润<=5000,提成15%,5000<利润<=10000,提成20%,利润<10000提成25%
麻烦高手看看错在哪了???
11 回复
#2
Lurking20202007-10-30 21:21

同样是新人 . . ... 帮你看下 .. .. .

#3
tywfeng2007-10-30 21:52
回复:(misschen)新手编程过程中的一个问题,求教
main()
{
float salory=500;
int profit;
printf("input profit\n");
scanf("%d",&profit);
if(profit<=1000)
{
salory+=salory;
}
if((profit>1000)&&(profit<=2000))
{
salory+=profit*0.1;
}
if((profit>2000)&&(profit<=5000)) //不是profit<2000,应该是profit>2000
{
salory+=profit*0.15;
}
if((profit>5000)&&(profit<=10000)) //不是profit<5000,应该是profit>5000
{
salory+=profit*0.20;
}
if(profit>10000)
{
salory+=profit*0.25;
}
printf("salary=%f\n",salory);
getch();
}
#4
tywfeng2007-10-30 21:56

晕,只是把一个地方的错误给改过来了,还有的地方没找到

#5
tywfeng2007-10-30 22:04

终于看懂了。上面的那个把int改成long,把%d改成%ld就行了。

[此贴子已经被作者于2007-10-30 22:17:14编辑过]

#6
misschen2007-10-30 22:12
好象不对
#7
w30260932007-10-30 22:30

main()
{float salory=500;
float profit;
printf("input profit\n");
scanf("%f",&profit);
if(profit<=1000) salory+=salory;
else if((profit>1000)&&(profit<=2000)) salory+=profit*0.1;
else if((profit<2000)&&(profit<=5000)) salory+=profit*0.15;
else if((profit<5000)&&(profit<=10000)) salory+=profit*0.20;
else salory+=profit*0.25;
printf("salary=%f\n",salory);
}

有多个IF出现,要有对应的ELSE

#8
misschen2007-10-31 12:12
还是不对啊!!1
#9
不离不弃2007-10-31 17:07
既然小于1000时没提成 第一个IF后直接用;就可以了吧
不知道对不对
请指点哈!
#10
xiaxin2007-10-31 20:26
7楼的说法不对,一个模块中可以使用多个IF,而ELSE必须与IF配对使用.
其实是有效数字的问题
#include<stdio.h>
main()
{
double salory=500; //双精度型的有效数字比单精度的要高
int profit;
printf("input profit\n");
scanf("%d",&profit);
if(profit<=1000)
{
salory+=salory;
}
if((profit>1000)&&(profit<=2000))
{
salory+=profit*0.1;
}
if((profit>2000)&&(profit<=5000)) //不是profit<2000,应该是profit>2000
{
salory+=profit*0.15;
}
if((profit>5000)&&(profit<=10000)) //不是profit<5000,应该是profit>5000
{
salory+=profit*0.20;
}
if(profit>10000)
{
salory+=profit*0.25;
}
printf("salary=%lf\n",salory); //双精度对应的输出格式
getchar(); //注意关键字的拼写
}
#11
babylong58202007-10-31 21:20
哇..我也是新人,学习学习.
#12
为你呼吸2007-10-31 23:19

//帮你改过了,自己看,这么粗心!!!!
#include<stdio.h>
main()
{float salory=500;
long profit;
printf("input profit\n");
scanf("%d",&profit);
if(profit<=1000) {salory+=salory;}
else if((profit>1000)&&(profit<=2000)) {salory+=profit*0.1;}
else if((profit<2000)&&(profit<=5000)) {salory+=profit*0.15;}
else if((profit<5000)&&(profit<=10000)) {salory+=profit*0.20;}
else if(profit>10000) {salory+=profit*0.25;}
printf("salary=%f\n",salory);
}

1