這是源碼:
#include
void count(double profit);
int main()
{
double pro;
//printf("請輸入利潤:");
//scanf("%f",pro); //為什麼不能輸入????????????
count(660000);
return 0;
}
void count(double profit)
{
double prize[5];
double bonus;
int pro = profit/10000;
prize[0] = 100000*10*0.01;
prize[1] = prize[0]+100000*7.5*0.01;
prize[2] = prize[1]+200000*5*0.01;
prize[3] = prize[2]+200000*3*0.01;
prize[4] = prize[3]+400000*1.5*0.01;
if(pro<=10)
{
bonus = pro*0.1;
}
else if(pro<=20)
{
bonus = prize[0]+(profit-100000)*0.075;
}
else if(pro<=40)
{
bonus = prize[1]+(profit-200000)*0.05;
}
else if(pro<=60)
{
bonus = prize[2]+(profit-400000)*0.03;
}
else if(pro<=100)
{
bonus = prize[3]+(profit-600000)*0.015;
}
else if(pro>100)
{
bonus = prize[4]+(profit-1000000)*0.01;
}
printf("當月獎金為:%f",bonus);
}
不知道為什麼去掉注釋之後,並把 count(660000);改為 count(pro);之後,程序不能得到理想運行結果
這樣寫當然不對scanf("%f",pro);
首先double的占位符應當是%lf,其次pro應該加上取地址符
改為:
scanf("%lf",&pro);