some confusion on where to insert the "static_cast"

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;
}
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
I'm trying to convert the degrees in double fahrenheit to degrees in int celsius, i'm just not sure where to convert
You don't need any casting, remove all the casting stuff and run your program.
yes you do. i'm getting conversion errors
This is your code without that damned casting stuff a few other corrections. It works fine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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 main()
{
    double fahrenheit = 0.0;
    int celsius = 0;

    fahrenheit = getFahrenheit ();
    celsius = calcCelsius (fahrenheit);

    cout << fixed << setprecision(0) << celsius;

    return 0;
} //end of main function

//*****function definitions*****
double getFahrenheit()
{
    double fahrenheit = 0.0;
    cout << "Enter Fahrenheit temperature: ";
    cin >> fahrenheit;
    return fahrenheit;
}
int calcCelsius (double fahrenheit)
{
    int celsius = 0;
    celsius = 5.0/9.0 * (fahrenheit - 32.0);
    return celsius;
}
Owesome!
Thank you Bazzy!
I hate using that static_cast stuff
Topic archived. No new replies allowed.