내 프로그램은 온도를 화씨 눈금에서 섭씨 눈금으로, 마지막으로 절대 값 눈금으로 변환합니다.
#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";
이 오류가 발생하는 이유는 무엇입니까?
ab
a를 취하고 a float
를 반환합니다 float
.
float ab(float a)
그러나 cels
는 아닙니다 float
. 함수입니다.
float cels(int a)
당신은 아마도
ab(cels(farh))
또는 임시로 :
float cur_cels = cels(farh);
cout << farh << cur_cels << ab(cur_cels) << "\n";
참고 ab
로 이름은 kelvin
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다