### Temperature conversion issues.

Write a temperature conversion program that asks the user to choose between Celsius-to-Fahrenheit conversion or Fahrenheit-to-Celsius conversion. The user will also have the option to quit the program.

**If an incorrect choice is typed, display an error message and prompt the user to re-enter his/her choice.

** Depending on the choice, use the following formulas accordingly:
_Formula to convert from Celsius to Fahrenheit: 9.0/5.0*C+32.
_Formula to convert from Fahrenheit to Celsius: 5.0*(F-32)/9.0

((I have done the code but to get the calculation to work is a pain in my butt, and i needed help. Why isn't it calculating correctly, did i not declare correctly or am i putting the formula wrong. also need help with when user chooses an incorrect choice and displays and error message and adding a quit to the program.))

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include #include using namespace std; int main() { //Declare float d, n, Fa, Ce; char choice, F, C; //Question { cout << "Enter F- Fahrenheit\n"; cout << "Enter C- Celsius\n"; cout<< "Enter Q- Quit\n:"; cin >> choice; } //Formula C = n; F = n; Fa= 9.0/5.0*C+32 ; Ce= 5.0*(F-32)/9.0 ; //choices if (choice == 'C') { cout << "Enter Degrees: "; cin >> n; cout<< "The degrees in Farenheit is:" << Fa << "\n"; } else if (choice == 'F') { cout << "Enter Degrees: "; cin >> n; cout << "The degrees in Celsius is:" << Ce << "\n"; } else if (choice == 'Q') { cout << "Exiting......Good Bye"; } cout << endl; return 0; } ``````
On line 20 and 21 you assign random values to C and F.
How can you expect any correct result and line 23 and 25?
After you get the input on line 38 you are not doing anything with it.
How do i get the program to respond to the formulas...

 ``12345678910111213141516171819`` `````` cout << "Enter Degrees: "; cin >> n; degF= 9.0/5.0*n+32 ; cout<< "The degrees in Farenheit is:" << degF << "\n"; } else if (choice == 'F') { cout << "Enter Degrees: "; cin >> n; degC= 5.0*(n-32)/9.0 ; cout << "The degrees in Celsius is:" << degC<< "\n"; ``````

??????
I've altered you're program to make it more straight forward
You are declaring variables all over the place, when you don't need to.

 If an incorrect choice is typed, display an error message and prompt the user to re-enter his/her choice.
You've not attempted this!

Have you learnt about fuctions and returning a variable?
Think about putting the first set of questions in to functions.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include using namespace std; int main() { //Declare float n;//, Fa, Ce, d char choice;//, F, C; //Question cout << "Enter F- Fahrenheit\n"; cout << "Enter C- Celsius\n"; cout<< "Enter Q- Quit\n:"; cin >> choice; //You only have to do this once cout << "Enter Degrees: "; cin >> n; //Formula //C = n; //F = n; //Fa= 9.0/5.0*C+32 ; //Ce= 5.0*(F-32)/9.0 ; //choices if (choice == 'C') { //cout << "Enter Degrees: "; //cin >> n; //Fa = 9.0/5.0*n+32 ; cout<< "The degrees in Farenheit is: " << 9.0/5.0*n+32 << "\n"; } else if (choice == 'F') { //cout << "Enter Degrees: "; //cin >> n; //Ce = 5.0*(n-32)/9.0 ; cout << "The degrees in Celsius is: " << 5.0*(n-32)/9.0 << "\n"; } else if (choice == 'Q') { cout << "Exiting......Good Bye"; } cout << endl; return 0; }``````

 ``12345678`` ``````Enter F- Fahrenheit Enter C- Celsius Enter Q- Quit :F Enter Degrees: 212 The degrees in Celsius is: 100 Press to close this window...``````

Last edited on
Topic archived. No new replies allowed.