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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define number .55555555555555555555555555555555555555555
using namespace std;
void setTempKelvin(double degreek,double degreec,double degreef,char type)
{
if(type == 'c')
{
degreek = degreec + 273.15;
}
else if(type == 'f')
{
degreec = degreef * number - 32;
degreek = degreec + 273.15;
}
cout << degreek;
}
void setTempFahrenheit(double degreef,double degreec,double degreek,char type)
{
if(type == 'c')
{
degreef = degreec * 1.8 + 32;
}
else if(type == 'k')
{
degreec = degreek - 273.15;
degreef = degreec * 1.8 + 32;
}
cout << degreef;
}
void setTempCelsius(double degreec,double degreef,double degreek,char type)
{
if(type == 'f')
{
degreec = degreef * number - 32;
}
else if(type == 'k')
{
degreec = degreek - 273.15;
}
cout << degreec;
}
int main()
{
double input, degreef = 0, degreek = 0, degreec = 0;
int type;
char t;
cout << "Which kind of temperature would you like to enter?"<< endl;
cout << "(Kelvin(1), Fahrenheit(2), Celsius(3)): ";
cin >> type;
switch(type)
{
case 1:
cout << "Enter your temperature: ";
cin >> input;
degreek = input;
break;
case 2:
cout << "Enter your temperature: ";
cin >> input;
degreef = input;
break;
case 3:
cout <<"Enter your temperature: ";
cin >> input;
degreec = input;
break;
default:
cout << "You have entered something invalid" << endl;
cout << "This program will now end " << endl;
return 0;
}
switch(type)
{
case 1:
t = 'k';
break;
case 2:
t = 'f';
break;
case 3:
t = 'c';
break;
}
cout << "Your temperature in Kelvin is ";
if(type != 1)
{
setTempKelvin(degreek,degreec,degreef,t);
}
else
{
cout << input;
}
cout << endl;
cout << "Your temperature in Celsius is ";
if(type != 3)
{
setTempCelsius(degreef,degreec,degreek,t);
}
else
{
cout << input;
}
cout << endl;
cout << "Your temperature in Fahrenheit is ";
if(type != 2)
{
setTempFahrenheit(degreef,degreec,degreek,t);
}
else
{
cout << input;
}
cout << endl;
return 0;
}
|