### I dont know why this function is not working. Could you tell me how to get it to work.

its a simple tempertature conversion code. I know that it is for the most part incomplete for the second half of the code. I want it to print out with the
fahrenheit temperature on one side and the celsius on another, while still using at least one function.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192`` ``````#include #include #include #include using namespace std; double calcfahrenheit (double start, double end, double between); double calccelsius(double start, double end, double between); double calcf(double celsius); int main() { int choice; double tstart, tend, tinterval; double fahrenheit; cout << "Which Temperature Scale Converstion Would You Like To Perform?\n"; cout << "1. Convert F to C\n"; cout << "2. Convert C to F\n"; cout << endl; cout << "What is your choice? "; cin >> choice; cout << endl; switch(choice) { case 1: cout << "Starting Temperature: "; cin >> tstart; cout << "Ending Temperature: "; cin >> tend; cout << "Temperture Increase: "; cin >> tinterval; cout << "Fahrenheit" << setw(12) << "Celsius\n"; cout << "----------" << setw(12) << "-------\n"; fahrenheit = calcfahrenheit(tstart,tend, tinterval); cout << tstart << setw(10) << fahrenheit << endl; break; case 2: cout << "Starting Temperature: "; cin >> tstart; cout << "Ending Temperature: "; cin >> tend; cout << "Temperture Increase: "; cin >> tinterval; cout << "Celsius" << setw(12) << "Fahrenheit\n"; cout << "-------" << setw(12) << "----------\n"; calccelsius(tstart, tend, tinterval); break; default: cout << "You entered an incorrect code\n"; break; } system("pause"); return 0; } double calcfahrenheit(double start, double end, double between) { double hope; for(start; start <= end; start += between) { calcf(faith) hope = calcf(faith); cout << start << setw(12) << hope << endl; } return start; } double calccelsius(double start, double end, double between) { for(start; start <= end; start += between) { cout << start << setw(12) << end << endl; } return start; } double calcf(double faith) { double constant = 32; double multi1 = 9.0; double multi2 = 5.0; double quotiant; double sum; double please; please = calcfahrenheit(tstart, tend, tbetween); sum = please - constant; quotiant = multi1/multi2; faith = sum*quotiant; } ``````
you over complicate things. Read this:

http://en.wikipedia.org/wiki/Fahrenheit

line 87 makes no sense at all.
You need to think of much more sensible names. That will make you see how things work.

So if you want to calculate fahrenheit from Celsius, name the function like so:
 ``1234`` ``````double GetFahrenheitFromCelsius(double celsius) { return celsius * 9 / 5 + 32; }``````
This code would be much easier if you put most of your code inside of your functions. You are also asking for too much information. All you need is the number that the user wants converted, then convert and output within your functions. No need for start, end or increase. Code is suppose to be simple and efficient, not long and complicated.
And you shouldn't use doubles in for loops.

Floating point values are stored as binary fractions and cannot represent every real number. When you initialise a FP number X, you usually get X +/- a small amount - for doubles this is about 1e-16, this number is known as epsilon when X is 1.0. The for loop can fail on the end condition (or at least do 1 more iteration than what you thought) because the number can be less than the exact value by the epsilon amount.

So, always use integers in loop conditions & convert them to double inside the loop.

Hope all goes well.
Topic archived. No new replies allowed.