/* This program illustrates the definition and use of a very simple function to convert Fahrenheit temperatures into Celsius */ #include /* The following line is the prototype for the Fahr2Cel function. It basically "declares" the existance of the function, telling C what types the function takes as parameters and returns. */ float Fahr2Cel(float); /* The main function will prompt the user for the Fahrenheit temperature, and get the corresponding Celsius temperature by calling the function */ main() { float f, /* Fahrenheit temperature entered by user */ c; /* Celsius temperature printed to screen */ cout << "Enter a Fahrenheit temperature: "; cin >> f; /* The function call. We pass the Fahrenheit temperature entered by the user to the function, and store the value returned by the function in c. */ c = Fahr2Cel(f); cout << "The corresponding Celsius temperature is " << c << "\n"; } /* end of main function */ /* The Fahr2Cel function takes a float value as a parameter, and stores it in the variable fahr_temp. It then uses that variable to compute cel_temp, which it then returns to the caller */ float Fahr2Cel(float fahr_temp) { /* cel_temp is a local variable of Fahr2Cel (as is fahr_temp) */ float cel_temp; /* use the parameter to compute cel_temp */ cel_temp = 5 * (fahr_temp - 32)/9; /* return the value of cel_temp to the caller */ return cel_temp; } /* end of Fahr2Cel function