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.))

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
47
48
49
50
51
52
53
#include <iostream>
#include <cmath>

 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...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

 
  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.

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
47
48
49
#include <iostream>
#include <cmath>

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;
}

1
2
3
4
5
6
7
8
Enter F- Fahrenheit
Enter C- Celsius
Enter Q- Quit
:F
Enter Degrees: 212
The degrees in Celsius is: 100

Press <RETURN> to close this window...



Last edited on
Topic archived. No new replies allowed.