In: Computer Science
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit. The program will then convert the values into Kelvin (using 5/9 (Fº-32) to convert to Celsius and a difference of 273.15 between Celsius and Kelvin) and print out the new total value.
Convert temperature in Fahrenheit to Kelvin :
Enter temperature in Fahrenheit: 80.33
The temperature in Kelvin is: 300
Write a second program which then does the reverse conversion (using a difference of 273.15 between Celsius and Kelvin, and 9/5 (Cº+32) to convert from Celsius).A typical run and the expected output of your program would look like this:
Convert temperature in Fahrenheit to Kelvin :
Enter temperature in Kelvin: 300
The temperature in Fahrenheit: 80.33
Solution:
First Program:
#include <iostream>
using namespace std;
int main()
{
//declare variables
float kelvin, fahrenheit;
cout << "Convert temperature in Fahrenheit to Kelvin:\n";
cout << "Enter temperature in Fahrenheit: ";
//read in data from the standard input stream (cin)
cin >> fahrenheit;
//convert temperature into kelvin
kelvin = (5.0 / 9) * (fahrenheit - 32) + 273.15;
//print output
cout << "The temperature in Kelvin is: " << kelvin << endl;
return 0;
}
Output:
Second Program:
#include <iostream>
using namespace std;
int main()
{
//declare variables
float kelvin, fahrenheit;
cout << "Convert temperature in kelvin to Fahrenheit:\n";
cout << "Enter temperature in Kelvin: ";
//read in data from the standard input stream (cin)
cin >> kelvin;
//convert temperature into kelvin
fahrenheit = (kelvin - 273.15 ) * 9.0 / 5 + 32;
//print output
cout << "The temperature in Fahrenheit is: " << fahrenheit << endl;
return 0;
}
Output:
Please give thumbsup, if you like it. Thanks.