temperature conversion loop

Jun 26, 2017 at 4:11am
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 Jun 26, 2017 at 5:43am
Jun 26, 2017 at 4:50am
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';
}

Jun 26, 2017 at 4:51am
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.
Jun 26, 2017 at 5:47am
I already googled them but they are vague.
Jun 26, 2017 at 5:59am
closed account (48T7M4Gy)
So where did the code come from in your post?
Jun 26, 2017 at 6:08am
I typed it out.
Jun 26, 2017 at 6:13am
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.