Using the switch statement, write a program that allows the user to convert either from degrees Celsius to Fahrenheit or degrees
Fahrenheit to Celsius. Use the following formulas:
degreesC = 5(degreesF-32)/9
degreesF = (9(degreesC)/5) + 32
Prompt the user to enter a temperature and either a 'C'(or 'c') for
Celsius or an 'F'(or 'f') for Fahrenheit: allow
either upper or lower case,
but if anything other than 'C', 'c', 'F', or 'f' is entered, print an error
message that tells the user how to enter a valid selection (upper or lower case 'C' or 'F').
the code
/01 #include <iostream>
02 #include <windows.h>
03 using namespace std;
04
05 char F, C, M;
06 int Ct, Ft, T;
07
08 int main()
09 {
10 char wait4User;
11 do{
12 cout << "Please enter which option you would like to use : \n";
13 cout << "Fahrenheit = F \n";
14 cout << "Celsuis = C \n";
15 cout << "Exit = E \n";
16 cin >> M;
17 if (M == 'F' || M == 'f') {
18 do {
19 cout << "Please enter the temperature in Fahrenheit (999 returns to menu): ";
20 cin >> T;
21 if (T != 999){
22 Ct = (T - 32) * 5/9;
23 cout << "The tempurate in Celsius is : " << Ct << "\n";
24 }
25 if (T == 999){
26 break;
27 }
28 }while (T != 999);
29 }
30 if (M == 'C' || M == 'c') {
31 do {
32 cout << "Please enter the temperature in Celsius (999 returns to menu): ";
33 cin >> T;
34 if (T != 999){
35 Ft = T * 9/5 + 32;
36 cout << "The tempurate in Farenheit is : " << Ft << "\n";
37 }
38 if (T == 999){
39 break;
40 }
41 }while (T != 999);
42 }
43 }while (M != 'E' || M != 'e');
44 if (M == 'E' || M == 'e'){
45 return 0;
46 }
47 cin >> wait4User;
48 return 0;
49 }
You haven't asked a question. But, if you were wondering why the program doesn't end when you pressed the 'E', it's because you are checking for the 'E' with an OR instead of an AND.
Line 43 should look like }while (M != 'E' && M != 'e');