1
我似乎無法在我的printf語句中找出這個錯誤。每當我將整數格式說明符浮動,反之亦然,我只是得到同樣的錯誤。錯誤:格式%d期望類型爲int,但參數2的類型爲double(*)(int,int)
error: format â%fâ expects type âdoubleâ, but argument 2 has type âdouble (*)(int, int)â
這裏是我的代碼
void outputScores(int x, int y)
{
if(((x&y)>=1) && ((x&y)<=20))
{
printf("------------------------------\n");
printf("\n");
printf("Field: %d,%d\n",x,y);
printf("\n");
printf("Soil quality: %f\n",soilQuality);
printf("Sun exposure: %d\n",sunExposure);
printf("Irrigation exposure: %d\n",irrigationExposure);
printf("\n");
printf("Estimated yield: %d\n",estimatedYield);
printf("Estimated quality: %d\n",estimatedQuality);
printf("Time to harvest: %d\n",harvestTime);
printf("\n");
printf("Overall Score: %f\n",fieldScore);
printf("\n");
printf("------------------------------\n");
}
else
{
printf("Field %d, %d is invalid!\n",x,y);
}
return;
}
一部分,這裏是功能
double soilQuality(int x, int y)
{
if((x>=1) && (x<=20) && (y>=1) && (y<=20))
{
if((x+y)%2==1)
{
int soilQuality=(1+(sqrt((x-10)*(x-10))+((y-10)*(y-10))));
return soilQuality;
}
else
{
int soilQuality=(1+((abs(x-10)+abs(y-10))/2));
return soilQuality;
}
}
else
{
return -1;
}
}