My program converts temperature from F to C and vice versa. An option to also show the Kelvin units is also given and must be shown after the previous conversion. I'm having trouble with the function and function call for that.
This is a sample of how the program should run.
Welcome to the Temperature Converter!
Would you like to see degrees Kelvin (K) in the results? (Y/N): Y
Select conversion type (1=F to C, 2=C to F, 0=end): 1
Enter your Fahrenheit temperature: 32
A temp of 32 Fahrenheit converted to Celsius = 0 C.
This is also a temperature of: 273.15 K
Select conversion type (1=F to C, 2=C to F, 0=end): 2
Enter your Celsius temperature: 100
A temp of 100 Celsius converted to Fahrenheit = 212 F.
This is also a temperature of: 373.15 K
Select conversion type (1=F to C, 2=C to F, 0=end): 0
Thanks for using the temperature converter!
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
|
#include "stdafx.h"
#include <iostream>
using namespace std;
using namespace System;
double FtoC(double t);
double CtoF(double t);
double showDegreesK(double j);
int main()
{
double temp, result, kresult;
int choice, kchoice;
cout << "Welcome to the temp conversion program." << endl;
do
{
cout << "Would you like to see degrees Kelvin (K) in the results? (Y/N): ";
cin >> kchoice;
cout << "\nConversion Type (1=F to C, 2=C to F, 0=Quit: ";
cin >> choice;
if (choice == 1)
{
cout << "Enter your Fahrenheit temp: ";
cin >> temp;
result = FtoC(temp);
cout << "A temp of " << temp << "F is equal to " << result << "C." << endl;
showDegreesK(kchoice);
}
else if (choice == 2)
{
cout << "Enter your Celcius temp: ";
cin >> temp;
result = CtoF(temp);
cout << "A temp of " << temp << "C is equal to " << result << "F." << endl;
showDegreesK(kchoice);
}
} while (choice != 0);
cout << "\nThanks for using the temp converter!" << endl;
system("Pause");
return 0;
}
double FtoC(double t)
{
double r;
r = (5.0/9.0 * (t - 32.0));
return r;
}
double CtoF(double t)
{
double r;
r = ((9.0 / 5.0) * t) + 32;
return r;
}
double showDegreesK(double j, int choice, int kchoice, double result)
{
double kresult;
if (kchoice == 'Y' && choice == 1)
{
kresult = result + 273.15;
}
else if (kchoice == 'Y' && choice == 2)
{
kresult = (result + 459.67) * (5.0/9.0);
}
return kresult;
}
|