coady havens coady havens - 1 month ago 20
C Question

Easy C Program Error

im writing a very simple program to display mock weather data for a class and i cant figure out why visual studio keeps giving me an error

the error is on temperature through direction its telling me: error C2440: '=' : cannot convert from 'double (__cdecl *)(void)' to 'double'

im lost please help

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;
}

Answer

You missed parenthesis at this:

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

It should be like:

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