temperature conversion loop

I do not know how to start this program.
I have to do a while loop and convert temperatures.
I also need to prime the loop.

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
  #include <iostream>

using namespace std;

int main()
{
	char temp;
	char F, C, K, N, X;
	float celsius;
	float fahrenheit;
	float kelvin;
	float newton;

	//Formulas
	celsius = (fahrenheit - 32) * 5 / 9;
	kelvin = (fahrenheit - 32) * 5 / 9 + 273.15;


	cout << "This temperature conversion program converts other temperatures to Fahrenheit" << endl;
	cout << "The temperature types are:" << endl;
	cout << "C - Celsius " << endl;
	cout << "K - Kelvin " << endl;
	cout << "N - Newton " << endl;
	cout << "X - Exit " << endl;
	cout << "To use the converter you must input a value and one of the temperature types. " << endl;
	cout << "For example 32 C converts 32 degress from Celsius to Fahrenheit " << endl;
	cout << "Please enter a value and it's type to be converted " << endl;
	cin >> temp;


	
	cout << "Tn Celsius the temperature is " << celsius << endl;
	cout << "In Kelvin the temperature is " << kelvin << endl;
	return 0;

}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
double value;
char unit;
usage();
while(std::cin>>value>>unit){
   double fahrenheit;
   switch(unit){
   case 'C': fahrenheit = celsius_to_fahrenheit(value); break;
   case 'K': fahrenheit = kelvin_to_fahrenheit(value); break;
   case 'N': fahrenheit = newton_to_fahrenheit(value); break;
   case 'X': exit(0);
   }
   std::cout << "Temperature in fahrenheit " << fahrenheit << '\n';
}

closed account (48T7M4Gy)
Save us and yourself a whole lot of trouble.

Select lines 22 to 30 inclusive and google it. There are lots of solutions to this all over the net. Then cut, paste, submit.
I already googled them but they are vague.
closed account (48T7M4Gy)
So where did the code come from in your post?
I typed it out.
closed account (48T7M4Gy)
I typed it out.

You must be fairly tired seeing that you started in 2013! Probably explains why you forgot that you'd already done the while loop.

https://stackoverflow.com/questions/19217174/simple-function-c/19217241
Topic archived. No new replies allowed.