Global variable - lastTemperature "undeclared identifier"


#1

I am getting an “undeclared identifier” error with the global variable addition to the Fahrenheit/Celsius exercise. I have looked at my code and it looks like it reads in the book. Any ideas? Thanks in advance.

[code]#include <stdio.h>
#include <stdlib.h>

//Declare a global variable float lastTemperature;

float fahrenheitFromCelsius(float cel)
{

lastTemperature = cel;
float fahr = cel * 1.8 + 32.0;
printf("%f Celsius is %f Fahrenheit\n", cel, fahr);
return fahr;

}
[/code]

Here is the second half of the code, as it is getting cut off in the forum tool:

[code]int main(int argc, const char * argv[])
{

float freezeInC = 0;
float freezeInF = fahrenheitFromCelsius(freezeInC);
printf("Water freezes at %f degrees Fahrenheit\n", freezeInF);
printf("The last temperature converted was %f\n", lastTemperature);
return EXIT_SUCCESS;

}[/code]


#2

It doesn’t because the declaration of the global variable is missing.

Change this:

//Declare a global variable float lastTemperature;
...

To:

// Declare a global variable for last temperature
float lastTemperature;
...

#3

Tunnel vision from learning how to do this stuff in the wee hours of the morning. Thanks for the help.