Another new coder here, and yes, I am a student. I am NOT asking for a solution, but I am asking for guidance to point me in the right direction. I am supposed to write a code that receives input from the terminal as to the temperature in Fahrenheit and the wind speed in meters per second. Then use 3 sub functions to 1) convert Fahrenheit to Celsius, 2) calculate windchill, and 3) convert from Celsius back to Fahrenheit. Then output the results if the temperature in C is less than or equal to 10 degrees. I have written the code and added debugging comments to show the value of the variables throughout the calculations and no matter what is inputted, the degrees C (variable "tempC") always comes out to zero. Can someone help me find my error with the code below and point me in the right direction to correcting this part. I'm in hopes that I can debug the rest once I discover the reason for 0 degrees Celsius. *NOTE* the calls for the sub routines are a "given" in the assignment which is what has resulted in a loss of precision in the conversion from double to int during the calls...
#include <iostream>
#include <cmath>
using namespace std;
double windChill(double v, double t);
//Computes windchill
double f2c(int tempF);
//Converts Farenheit to Celcius
double c2f(int tempC);
//Converts Celcius to Farenheidt
int main( )
{
double t, // t used for temperature in Farenheidt
v, // v used for velocity in meters per second
W; // windchill factor in degrees Celsius
int tempF, // temperature in F used for windchill calculation
tempC; // temperature in C used for windchill calculation;
cout << "Enter the temperature in Farenheit: ";
cin >> t; // accept t from user
cout << "Enter the wind velocity in meters per second (m/s): ";
cin >> v; // accept v from user
cout << "temp in F is " << t << endl;
cout << "windspeed is " << v << endl;
tempC = f2c(t); // call function to convert F to C
cout << "Temp in C is : " << tempC << endl;
if (tempC <= 10) // test if degrees C is less than 10 and execute this portion if true.
{
W = windChill(v, tempC); // calculate windchill
cout << "Windchill is : " << W << endl;
tempF = c2f(tempC); // convert windchill to Farenheidt
cout << "Temp in F after windchill is : " << tempF << endl;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "The windchill is " << W << " degrees Celcius\n";
cout << "and " << tempF << " degrees Farenheidt.";
return(0);
} // end of if
else // return error that degrees in C is less than 10 and windchill is negligiable
{
cout << "The Farenheidt temperature you entered is less than 10 degrees Celcius.\nWindchill is negligable.";
return (0);
}
}
double windChill(double v, double t)
{
double W; //wind chill intex
W = (33-(((10 * sqrt(v))-v+10.5)*(33-t))/23.1);
return W;
}
double f2c(int tempF)
{
double tempC;
tempC = (5/9)*(tempF + 32);
return tempC;
}
double c2f(int tempC)
{
double tempF;
tempF = (9/5)*(tempC - 32);
return tempF;
}