Hello again,
I have this question which I don't understand and need help here.
1) I have this function double covertD(double, int)
, which takes in two arguements and returns a double. It will have to convert between Fahrenheit and Celsius and vice versa. This conversion depends on the passed in integer value.
Test case 1
If the passed in values are 212.0 and 1, the function converts the temperature 212.0 to Celsius.
Test case 2
If the passed in values are 100.0 and 2, the function converts the temperature 100.0 to Fahrenheit.
How do I write the heading and function body?
I dont understand the whole qns.
The passed in values in the test cases 212 and 100 are the temperautres, how about the 1 and 2? what are the passed in values actually - user inputs?
Thanks in advance!
from jeff's advice, i tried the following:
#include <iostream>
double degC = ((degF - 32) * 5/9);
double degF = ((degC * 9/5) + 32);
double covertDegrees(double value, int type) {
double temp_out = 0.0;
if (type == 1) {
// Fahrenheit to Celsius.
degC = value;
temp_out = degF// Formula here.
} else if (type == 2) {
// Celsius to Fahrenheit.
degF = value;
temp_out = degC// Formula here.
} else {
// Error.
cout << "error" << endl;
}
return temp_out;
}
im very noob at c++. is this correct?