Alright, my homework assignment is by using separate function definitions convert a temperature from Fahrenheit to Celcius.
I've looked over the whole chapter, looked at the examples, and am having trouble somewhere. My program will only convert one temperature correctly to Celcius, which is 32, because it always returns a value of 0.
Can someone look over it and see where I went wrong? As far as I can tell it should work, but it doesn't.
//Ch9AppE01.cpp
//Converts a Fahrenheit temperature
//to a Celsius temperature
//Created/revised by Greg Schader on 7/5/09
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::fixed;
//function prototypes
int getFahrenheit();
int calcCelcius(int);
int main()
{
//Define Variables.
int degFahrenheit = 0;
int degCelcius = 0;
degFahrenheit = getFahrenheit();
degCelcius = calcCelcius(degFahrenheit);
cout << fixed << setprecision(0) << "Temperature in Celcius: " << degCelcius << endl;
return 0;
} //end of main function
//*****function definitions*****
int getFahrenheit()
{
int degFahrenheit = 0;
cout << "Enter the temperature in Fahrenheit: ";
cin >> degFahrenheit;
return degFahrenheit;
}
int calcCelcius(int degFahrenheit)
{
int degCelcius = 0;
degCelcius = 5 / 9 * (degFahrenheit - 32);
return degCelcius;
}