Nov 9, 2009 at 4:50pm
I'm just now learning to use functions. I know I probably put the static_cast converter in the wrong places, can anyone direct me>
//Converts a Fahrenheit temperature
//to a Celsius temperature
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::fixed;
//function prototypes
double getFahrenheit ();
int calcCelsius(double, int);
int main()
{
double fahrenheit = 0.0;
int celsius = 0;
fahrenheit = getFahrenheit ();
celsius = calcCelsius ();
cout << fixed << setprecision(0);
return 0;
} //end of main function
//*****function definitions*****
double getFahrenheit()
{
double fahrenheit = 0.0;
cout << "Enter Fahrenheit temperature: ";
cin >> static_cast<int>(fahrenheit);
return fahrenheit;
}
int calcCelsius (double fahrenheit)
{
int celsius = 0;
celsius = static_cast<double>(fahrenheit)5.0/9.0 * (fahrenheit - 32.0);
return celsius;
}
Nov 9, 2009 at 5:07pm
cin >> static_cast<int>(fahrenheit);
Why are you doing this? Just cin >> fahrenheit;
( >> needs lvalues )
static_cast<double>(fahrenheit)
You don't need this as fahrenheit is already a double
Nov 9, 2009 at 9:14pm
I'm trying to convert the degrees in double fahrenheit to degrees in int celsius, i'm just not sure where to convert
Nov 9, 2009 at 9:29pm
You don't need any casting, remove all the casting stuff and run your program.
Nov 10, 2009 at 4:12am
yes you do. i'm getting conversion errors
Nov 10, 2009 at 3:47pm
Owesome!
Thank you Bazzy!
I hate using that static_cast stuff