Hello. I am currently taking an introduction to C++ programming class at my college, and we have to put together the most basic 2-Choice Temperature Conversion program.
The program works great for choice 1, "Fahrenheit to Celcius Converter". However, it doesn't work the other way around for choice 2 "Celcius to Fahrenheit".
I just can't figure out what I am doing wrong. It is required we use "Doubles" for Fahrenheit and Celcius. I have seen people use "Floats", but my professor hasn't gone over that in full. I even tried replacing (9.0 / 5.0) with just (1.8), but I am still getting incorrect calculation results. What can I do to adjust this?
Using meaningful variable names such as celsius and fahrenheit is much better than using anonymous letters such as p and q. But it seems you still got them in the wrong context several times.
It's weird how both cout statements require Fahrenheit as their variables,
That's what I was trying to say:
chervil wrote:
Using meaningful variable names such as celsius and fahrenheit is much better than using anonymous letters such as p and q. But it seems you still got them in the wrong context several times.
Line 23/24 are incorrect. It doesn't make sense to say that fahrenheit = (some conversion factor) fahrenheit.
It should be:
19 20 21 22 23 24 25
if (choice == 1) {
cout << "1. Fahrenheit to Celcius Converter" << endl;
cout << "Enter temperature in Fahrenheit: ";
cin >> fahrenheit;
celcius= (5.0 / 9.0)*(fahrenheit - 32.0);
cout << "Converted Celcius: " << celcius<< endl;
}
Also, I deliberately used the same spellings as the original code here - but note that Celsius - after the Swedish astronomer Anders Celsius is spelled with just one 'c' and two 's'es.