知道源代码,但是不能理解
??? 先完完全全按照题意写出代码,语法不会的话去看教科书,应该没有任何难度
程序代码:
double foo( double i )
{
double r = 0;
if( i <= 100000 )
r = i*0.100;
else if( i <= 200000 )
r = 100000*0.100 + (i-100000)*0.075;
else if( i <= 400000 )
r = 100000*0.100 + (200000-100000)*0.075 + (i-200000)*0.050;
else if( i <= 600000 )
r = 100000*0.100 + (200000-100000)*0.075 + (400000-200000)*0.050 + (i-400000)*0.030;
else if( i <= 1000000 )
r = 100000*0.100 + (200000-100000)*0.075 + (400000-200000)*0.050 + (600000-400000)*0.030 + (i-600000)*0.015;
else
r = 100000*0.100 + (200000-100000)*0.075 + (400000-200000)*0.050 + (600000-400000)*0.030 + (1000000-600000)*0.015 + (i-1000000)*0.010;
return r;
}
然后,有空余时间,可以化简代码
程序代码:
double foo( double i )
{
double r = 0;
if( i <= 100000 )
r = i*0.100 + 0;
else if( i <= 200000 )
r = i*0.075 + 2500;
else if( i <= 400000 )
r = i*0.050 + 7500;
else if( i <= 600000 )
r = i*0.030 + 15500;
else if( i <= 1000000 )
r = i*0.015 + 24500;
else
r = i*0.010 + 29500;
return r;
}