当前位置: 代码迷 >> C语言 >> [求助]新手请教C程序中出现的问题
  详细解决方案

[求助]新手请教C程序中出现的问题

热度:389   发布时间:2007-04-12 22:16:08.0
[求助]新手请教C程序中出现的问题
请教下这个程序出现的问题是什么原因

main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
scanf("%ld",&i);
bonus1=100000*0.1;bonus2=bonus1+100000*0.75;
bonus4=bonus2+200000*0.5;
bonus6=bonus4+200000*0.3;
bonus10=bonus6+400000*0.15;
 if(i<=100000)
  bonus=i*0.1;
 else if(i<=200000)
     bonus=bonus1+(i-100000)*0.075;
    else if(i<=400000)
        bonus=bonus2+(i-200000)*0.05;
       else if(i<=600000)
           bonus=bonus4+(i-400000)*0.03;
          else if(i<=1000000)
              bonus=bonus6+(i-600000)*0.015;
             else
              bonus=bonus10+(i-1000000)*0.01;
printf("bonus=%d",bonus);
}
搜索更多相关的解决方案: bonus  else  int  

----------------解决方案--------------------------------------------------------

你做的太不规范了
不好看!!~不晓得你写的是什么意思!!~~
有可能是我的水平有限吧~~~不好意思呀~~~


----------------解决方案--------------------------------------------------------
这么多IF,怎么不用SWITCH,那样方便点,要停电了,明天再看
----------------解决方案--------------------------------------------------------

int 型数据的范围 -32768~32767
bonus2=bonus1+100000*0.75;>75000
...


----------------解决方案--------------------------------------------------------
为什么要对同一级的else if缩进呢?显得很不清晰
----------------解决方案--------------------------------------------------------
程序中可能有双字节空格。
建议在每个if或else if语句后按delete键,一直删除到下一行语句的第一个字符为止,然后回车,重新设置缩进和对齐。
----------------解决方案--------------------------------------------------------
应该是这样吧:
main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
scanf("%ld",&i);
bonus1=100000*0.1;bonus2=bonus1+100000*0.75;
bonus4=bonus2+200000*0.5;
bonus6=bonus4+200000*0.3;
bonus10=bonus6+400000*0.15;
 if(i<=100000)
  bonus=i*0.1;
 else if(i>100000&&i<=200000)
     bonus=bonus1+(i-100000)*0.075;
    else if(i>200000&&i<=400000)
        bonus=bonus2+(i-200000)*0.05;
       else if(i>400000i<=600000)
           bonus=bonus4+(i-400000)*0.03;
          else if(i>600000&&i<=1000000)
              bonus=bonus6+(i-600000)*0.015;
             else if(i>100000)
              bonus=bonus10+(i-1000000)*0.01;
printf("bonus=%d",bonus);
}
我也是菜鸟...有错的地方大家表笑我额.....
----------------解决方案--------------------------------------------------------
我想应该是数据超出整形范围
----------------解决方案--------------------------------------------------------
不是有了long吗?long的长度好象可以超过32767吧
----------------解决方案--------------------------------------------------------
回复:(tj8355825)[求助]新手请教C程序中出现的问题...

我也是从网上下的100例上的结果运行时出错
题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高
   于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提
   成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于
   40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于
   100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?
1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。      
2.程序源代码:
main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
scanf("%ld",&i);
bonus1=100000*0.1;bonus2=bonus1+100000*0.75;
bonus4=bonus2+200000*0.5;
bonus6=bonus4+200000*0.3;
bonus10=bonus6+400000*0.15;
 if(i<=100000)
  bonus=i*0.1;
 else if(i<=200000)
     bonus=bonus1+(i-100000)*0.075;
    else if(i<=400000)
        bonus=bonus2+(i-200000)*0.05;
       else if(i<=600000)
           bonus=bonus4+(i-400000)*0.03;
          else if(i<=1000000)
              bonus=bonus6+(i-600000)*0.015;
             else
              bonus=bonus10+(i-1000000)*0.01;
printf("bonus=%d",bonus);
}

错误信息如下:

--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.C
F:\C++练习\1.C(5) : warning C4013: 'scanf' undefined; assuming extern returning int
F:\C++练习\1.C(6) : warning C4244: '=' : conversion from 'const double ' to 'int ', possible loss of data
F:\C++练习\1.C(6) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(7) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(8) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(9) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(10) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(10) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(11) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(11) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(11) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(11) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(11) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(12) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(12) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(13) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(14) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(15) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(16) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(17) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(18) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(19) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(19) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(19) : error C2018: unknown character '0xa1'
F:\C++练习\1.C(19) : fatal error C1003: error count exceeds 100; stopping compilation
执行 cl.exe 时出错.

1.exe - 1 error(s), 0 warning(s)


----------------解决方案--------------------------------------------------------
  相关解决方案