gpt4 book ai didi

c - 简单的 C 程序错误

转载 作者:行者123 更新时间:2023-11-30 19:37:21 24 4
gpt4 key购买 nike

我正在编写一个非常简单的程序来显示类的模拟天气数据,但我不明白为什么 Visual Studio 总是给我一个错误

错误在于温度,它告诉我:错误 C2440: '=' : 无法从 'double (__cdecl *)(void)' 转换为 'double'

我迷路了,请帮忙

void DisplayWeatherData(void)
{
double temperature,humidity,pressure,windspeed,direction,bt,bp,bw;

temperature = GetTemperature;
humidity = GetHumidity;
pressure = GetPressure;
windspeed = GetWindspeed;
direction = GetWindDirection;
bt = (temperature * 9.0 / 5.0) + 32.0;
bp = pressure * KPATOINHG;
bw = windspeed * KMTOMPH;


printf("\nTemperature: %4.1lf C\tHumidity: %3.0lf%%\tPressure: %4.1lf kPa\n",temperature,humidity,pressure);
printf("Windspeed: %3.0lf km/hr\tDirection: %3.0lf Degrees\n\n",windspeed,direction);

printf("\nTemperature: %4.1lf F\tHumidity: %3.0lf%%\tPressure: %4.1lf inHg\n",bt,humidity,bp);
printf("Windspeed: %3.0lf mph\tDirection: %3.0lf Degrees\n\n",bw,direction);


}

double GetTemperature(void)
{
return 25.1;
}
double GetHumidity(void)
{
return 55.4;
}
double GetPressure(void)
{
return 101.7;
}
double GetWindspeed(void)
{
return 15.5;
}
double GetWindDirection(void)
{
return 320.0;
}

最佳答案

您错过了括号:

temperature = GetTemperatur;
humidity = GetHumidity;
pressure = GetPressure;
windspeed = GetWindspeed;
direction = GetWindDirection;

应该是这样的:

temperature = GetTemperature();
.//same
.//same
.//same
direction = GetWindDirection();

关于c - 简单的 C 程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39967986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com