我的程序將溫度從華氏溫標轉換爲Celcius標度,最後轉換爲絕對值標尺。錯誤:無法將'float(*)(int)'轉換爲'float'
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int farh;
float cels(int a)
{
float c;
const int m0 = 32;
const float m1 = 0.5555;
c=(a-m0)/m1;
return c;
}
float ab(float a)
{
const float m2 = 273.15;
float d;
d=a-m2;
return d;
}
int main() {
const int WIDTH = 16;
cout << setiosflags (ios :: left);
cout << setw(WIDTH) << "Fahrenheit" << setw(WIDTH) << "Celcius" << setw(WIDTH) << "Absolute Value" << '\n';
cout.setf(ios::fixed);
cout.precision(2);
for (farh = 0 ; farh <= 300 ; farh = farh + 20) {
cout.width(16);
cout << farh << cels(farh) << ab(cels) << "\n";
}
return 0;
}
我收到編譯時錯誤信息是:
d26.cc: In function ‘int main()’:
d26.cc:38:40: error: cannot convert ‘float (*)(int)’ to ‘float’ for argument ‘1’ to ‘float ab(float)’
cout << farh << cels(farh) << ab(cels) << "\n";
我爲什麼會收到這個錯誤?
@BAarry 與ab(cels(farh))完美搭配。 –