此代码揭密了为何当国际油价在80与83.2之间徘徊时,中国油价却可以从6元一升涨到7.5一升
// 定义油价变更阀值,当国际油价在此阀值之内,不作油价调整
#define THRESHOLD 4.0
// 当前中国油价
#define CHINA 6.0
// 当前国际油价
#define INTER 80.0
float china = 6.0;
float inter = 80.0;
void Adjust(float curInter)
{
float change = (float)(curInter - inter) / (float)inter;
float absChange = change<0.0 ? -change:change;
if( absChange*100.0 > THRESHOLD-Accuracy ){
china = china + change*china;
printf("当前国际油价%s幅为: %.2f%% 满足调价条件\n", change>0? "涨":"跌" ,absChange*100.0);
}else{
printf("当前国际油价%s幅为: %.2f%% 不满足调价条件\n", change>0? "涨":"跌", absChange*100.0);
}
inter = curInter;
}
int main(int argc, char* argv[])
{
float curInter = 0.0;
while(1){
printf("当前国际油价 %.2f,当前中国油价 %.2f\n",inter,china);
printf("请输入当前国际油价: ");
scanf("%f",&curInter);
Adjust(curInter);
if(curInter < 1.0)break;
}
return 0;
}
|