Pass by reference not working

I don't understand why the function call (convertFtoC or convertCtoF) is not working. It seems like everything else is working but the function call is not accessing the function I created above.
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
41
42
43
44
45
46
#include <iostream>
using namespace std;

void convertFtoC( double& f )
{
    (f - 32) * 5.0/9.0;
}

void convertCtoF( double& c )
{
    (c + 32) * 9.0/5.0;
}


int main()
{
    char yorn;

    while (! ( (yorn == 'n') || (yorn == 'N') ) )
    {
        char answer;
        double fdeg, cdeg;

        cout << "Please enter C if you want to enter a degree in Centigrade, F if you want to enter a degree in Fahrenheit." << endl;
        cin >> answer;
        if ( (answer == 'C') || (answer == 'c') )
            {
                cout << "Please enter a number to be converted to Fahrenheit" << endl;
                cin >> cdeg;
                cout << "You entered " << cdeg << " Centigrade, ";
                convertCtoF(cdeg);
                cout << "which is " << cdeg << " Fahrenheit." << endl;
            }
        if ( (answer == 'F') || (answer == 'f') )
            {
                cout << "Please enter a number to be converted to Centigrade" << endl;
                cin >> fdeg;
                cout << "You entered " << fdeg << " Fahrenheit, ";
                convertFtoC(fdeg);
                cout << "which is " << fdeg << " Centigrade" << endl;
            }
        cout << "Do you want to do another conversion?" << endl;
        cin >> yorn;
    }
    return 0;
}
You don't actually do anything to the variables on lines 6 and 11. Use '=' to set f and c to whatever you need them to be.

1
2
3
f = (f - 32) * 5.0/9.0;

c = (c + 32) * 9.0/5.0;
Last edited on
thank you, something so simple
Topic archived. No new replies allowed.