我很新,所以我確信這是一個業餘的錯誤。我試圖做一個基本的金融計算器,並保持運行到這個錯誤,當我嘗試編譯:GCC參數類型錯誤?
findn.c:在函數「主」: findn.c:36:3:警告:格式「% f'需要類型爲'float *'的參數,但參數2的類型爲'double'[-Wformat] findn.c:50:3:warning:格式'%f'需要'float *'類型的參數,但參數2有類型'雙'[-Wformat]
據我所知,參數是一個浮點類型。是什麼賦予了?也可以隨意指出其他任何東西,我相信我的代碼是sl。不馴的。
#include <stdio.h>
#include <math.h>
void findN (float PV, float FV, float interest)
{
float iDec = interest/100;
float onePlusI = iDec + 1;
float leftSide = FV/PV;
float logOne = log(leftSide);
float logTwo = log(onePlusI);
float N = logOne/logTwo;
printf("%f\n", N);
}
void findI (float PV, float FV, float N)
{
float leftSide = FV/PV;
float expN = 1/N;
float iPlusOne = pow(leftSide, expN);
float iDec = iPlusOne - 1;
float interest = iPlusOne * 100;
printf("%f\n", interest);
}
main ()
{
int userInput;
printf("Press 1 to find Present Value, 2 to find Future Value, 3 to find Interest, or 4 to find Number of Periods\n");
scanf("%d", &userInput);
if (userInput = 3)
{
float Pres3;
float Fut3;
float Num3;
printf("Enter Present Value\n");
scanf("%f", Pres3);
printf("Enter Future Value\n");
scanf("%f", &Fut3);
printf("Enter the Number of Periods\n");
scanf("%f", &Num3);
findN(Pres3, Fut3, Num3);
}
else if (userInput = 4)
{
float Pres4;
float Fut4;
float Int4;
printf("Enter Present Value\n");
scanf("%f", Pres4);
printf("Enter Future Value\n");
scanf("%f", &Fut4);
printf("Enter interest\n");
scanf("%f", &Int4);
findN(Pres4, Fut4, Int4);
}
}
'Pres4'有同樣的問題btw –
是的,就是這樣。謝謝! – user2875108