Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
/* Program will ask user to input temperature in fahrenheit and
*convert it to celcius and kelvin
*By: Destiny Muldrow
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//set the variables (constant is used to convert to kelvin)
const double DIFFERENCE = 273.15;
double fahrenheit;
double celcius;
double kelvin;
//asks user for the temperature in fahrenhheit
cout << "Enter temperature in fahrenheit: ";
cin >> fahrenheit;
//calculate how to convert fahrenheit to celcius and kelvin
celcius = (fahrenheit - 32) / 1.8;
kelvin = celcius + DIFFERENCE;
//sets the decimal place to three places over
cout << fixed << setprecision(3);
//output the temperature in celcius and kelvin
cout << "Temperature in celsius is: " << celcius << endl;
cout << "Temperature in kelvin is: " << kelvin << endl;
return 0;
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more