Temperature Conversion problem

I decided to get an early start to this, and I seem to have a good amount of it worked out. My problem is that it says that my C, F, R and K are unidentified, and I'm not sure if my loop is properly placed/done. Any help would be well appreciated.


A program is required to convert a temperature that is expressed in one unit into a temperature of another unit.

The units the program must be designed to accept are:

K - Kelvin
C - Celsius
R - Rankine
F - Fahrenheit
A typical screen display for one value is shown below:

Input a temperature: 98.6
What are the units of that temperature: f
What are the units to convert to : c
98.6 °F is equivalent to 37 °C

Input a temperature: -40
What are the units of that temperature: c
What are the units to convert to : f
-40 °C is equivalent to -40 °F

Input a temperature: 0
What are the units of that temperature: x
What are the units to convert to : x

No further conversions are needed.

Press any key to continue . . .

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 //Temperature Conversion
//David Karayof
//October 10th 2013

#include <iostream>
#include <cmath>
using namespace std;

int main ()

{
//Define variables
	char choice1, choice2;
	double tK, tC, tR, tF;
	double temp;

	cout << "\nTemperature Conversion";
	cout << "\n\nInput a temperature: ";
	cin >> temp;
	cout << "\nWhat are the units of that temperature: ";
	cin >> choice1;
	
	while((choice1 == ('c' || 'C') || ('r' || 'R') || ('f' || 'F') || ('k' || 'K')) && choice2 == (('c' || 'C') || ('r' || 'R') || ('f' || 'F') || ('k' || 'K')))
	{
	if(choice1 = ('c' || 'C'))
	{
		choice1= C;
		tK = temp + 273.15;

	}

	else if(choice1 = ('f' || 'F'))
	{
		choice1 = F;
		tK = ((5 / 9) * (temp - 32) + 273.15);
	}

	else if(choice1 = ('r' || 'R'))
	{
		choice1 = R;
		tK = (temp / 1.8);
	}

	else if(choice1 = ('k' || 'K'))
	{
		choice1 = K;
		tK = temp;
	}

	cout << "\nWhat are the units to convert to: ";
	cin >> choice2;

	if (choice1 > 90) 
	choice1 -=32;
	
		else if(choice2 = ('c' || 'C'))
		{
			tC = tK - 273.15;
			cout << temp << " degrees "<< choice1 << " is equivalent to " << tC << " degrees C";  

		}

		else if(choice2 = ('f' || 'F'))
		{
			tF = (tK * 1.8) - 459.67;
			cout << temp << " degrees "<< choice1 << " is equivalent to " << tF << " degrees F";  

		}

		else if(choice2 = ('r' || 'R'))
		{
			tR = tK * 1.8;
			cout << temp << " degrees "<< choice1 << " is equivalent to " << tR << " degrees R";  

		}

		else if(choice2 = ('k' || 'K'))
		{
			tK = tK;
			cout << temp << " degrees "<< choice1 << " is equivalent to " << tK << " K";  

		}
		cout << "\n\n Input a temperature: ";
	cin >> choice1;
	(choice1 > 90); 
	 choice1 -=32;
	}

return 0;
}
Youi cant to:
while (choice1 == ('c' || 'f') )
Change it to:
while (choice1 == 'c' || choice1 == 'f')

And certainly never do:
while (choice = 'c' || choice = 'f')
Last edited on
I cleaned up the while loop to
 
while((choice1 == 'c' || choice1 == 'C' || choice1 == 'r' || choice1 == 'R' || choice1 == 'f' || choice1 == 'F' || choice1 == 'k' || choice1 == 'K') && (choice2 == 'c' || choice2 == 'C' || choice2 == 'r' || choice2 == 'R' || choice2 == 'f' || choice2 == 'F' || choice2 == 'k' || choice2 == 'K'));


but im not sure if i can include choice1 and choice2 in the while look; doesn't seem like it, as soon as i input c for choice1, the program gives me an error and closes.
I also fixed all the if statements (same problem as the while loop, i had to separate my choices) and my loop is now running and working perfectly once. Afterwards, it prompts me to input a temperature and units, then skips to giving me the conversion (which is incorrect) without asking what to convert it to.
Topic archived. No new replies allowed.