I need a quick bit of help with some C++ ( beginner )
I am taking an entry level C++ class and we are at the point where we are learning how to use if else statments
We are using Microsoft Visual C++ Basic
The program runs but does not perform the math ?????
And the assignment is as follows:
<b><big> Program Development</big></b>
I am taking an entry level C++ class and we are at the point where we are learning how to use if else statments
We are using Microsoft Visual C++ Basic
The program runs but does not perform the math ?????
And the assignment is as follows:
<b><big> Program Development</big></b>
A program is required to convert a temperature that is expressed in one unit, into a temperature of another unit.
The units the program must be designed to accept are:
*******************************
this is as far as I have gotten
************************
// john
// EN17
// temperture conversion homework
# include <iostream.h>
int main ()
{
// Decalre variables
double Temp_in , Temp_out ,TEMP_K;
char UNITS_in , UNITS_out,C,F,R,K;
// Prompt for Values
cout<< "This program will convert any temperature, from one unit to another";
cout<< "\n\nEnter the value of the temperature: ";
cin >> Temp_in;
cout<< "\n\nEnter the current units of the temperature\nfor Celcius, enter C:\nfor Farenheit, enter F:";
cout<< "\nfor Rankine, enter R\nfor Kelvine, enter K\n: ";
cin >> UNITS_in;
cout<< "\n\nEnter the units of temperature you want to convert to:\nfor Celcius, enter C:\nfor Farenheit, enter F:";
cout<< "\nfor Rankine, enter R:\nfor Kelvine, enter K:\n ";
cin >> UNITS_out;
// Temp K Calculations
if ( UNITS_in == C)
{
TEMP_K = Temp_in + 273.15; //UNITS_in = Celcius
}
else if ( UNITS_in == F)
{
TEMP_K = (Temp_in +459.67)*(5/9); //UNITS_in = Farenheit
}
else if ( UNITS_in == R)
{
TEMP_K = Temp_in *(5/9); //UNITS_in = Rankine
}
else if( UNITS_in == K )
{
TEMP_K = Temp_in ; //UNITS_in = Kelvine
}
// Temp out calulations
if ( UNITS_out == C)
{
Temp_out = TEMP_K - 273.15; //UNITS_out = Celcius
}
else if ( UNITS_out == F)
{
Temp_out = TEMP_K *(9/5)-459.67; //UNITS_out = Farenheit
}
else if ( UNITS_in == R)
{
Temp_out = TEMP_K *(5/9); //UNITS_out = Rankine
}
else (UNITS_in == K);
{
Temp_out = TEMP_K ; //UNITS_out = Kelvine
}
// Output Results
cout << "\nYour temperature of" << Temp_in <<" degrees" << UNITS_in << "when converted ";
cout << "\nresults in " << Temp_out << " degrees " << UNITS_out<<" \n ";
return 0;
}</iostream.h>
The units the program must be designed to accept are:
- K - Kelvin
- C - Celsius
- R - Rankine
- F - Fahrenheit
<big>This program will convert a temperature in units
of Celsius (C), Kelvin (K), Fahrenheit (F) or
Rankine (R), to a temperature in any of these units.
Input Temperature: 37
Units to convert from (C, K, F, R): c
Units to convert to (C, K, F, R): f
A temperature of 37 °C is equivalent to 98.6 °F.
Press any key to continue</big>
You should be able to input the units in either upper or lower case.of Celsius (C), Kelvin (K), Fahrenheit (F) or
Rankine (R), to a temperature in any of these units.
Input Temperature: 37
Units to convert from (C, K, F, R): c
Units to convert to (C, K, F, R): f
A temperature of 37 °C is equivalent to 98.6 °F.
Press any key to continue</big>
*******************************
this is as far as I have gotten
************************
// john
// EN17
// temperture conversion homework
# include <iostream.h>
int main ()
{
// Decalre variables
double Temp_in , Temp_out ,TEMP_K;
char UNITS_in , UNITS_out,C,F,R,K;
// Prompt for Values
cout<< "This program will convert any temperature, from one unit to another";
cout<< "\n\nEnter the value of the temperature: ";
cin >> Temp_in;
cout<< "\n\nEnter the current units of the temperature\nfor Celcius, enter C:\nfor Farenheit, enter F:";
cout<< "\nfor Rankine, enter R\nfor Kelvine, enter K\n: ";
cin >> UNITS_in;
cout<< "\n\nEnter the units of temperature you want to convert to:\nfor Celcius, enter C:\nfor Farenheit, enter F:";
cout<< "\nfor Rankine, enter R:\nfor Kelvine, enter K:\n ";
cin >> UNITS_out;
// Temp K Calculations
if ( UNITS_in == C)
{
TEMP_K = Temp_in + 273.15; //UNITS_in = Celcius
}
else if ( UNITS_in == F)
{
TEMP_K = (Temp_in +459.67)*(5/9); //UNITS_in = Farenheit
}
else if ( UNITS_in == R)
{
TEMP_K = Temp_in *(5/9); //UNITS_in = Rankine
}
else if( UNITS_in == K )
{
TEMP_K = Temp_in ; //UNITS_in = Kelvine
}
// Temp out calulations
if ( UNITS_out == C)
{
Temp_out = TEMP_K - 273.15; //UNITS_out = Celcius
}
else if ( UNITS_out == F)
{
Temp_out = TEMP_K *(9/5)-459.67; //UNITS_out = Farenheit
}
else if ( UNITS_in == R)
{
Temp_out = TEMP_K *(5/9); //UNITS_out = Rankine
}
else (UNITS_in == K);
{
Temp_out = TEMP_K ; //UNITS_out = Kelvine
}
// Output Results
cout << "\nYour temperature of" << Temp_in <<" degrees" << UNITS_in << "when converted ";
cout << "\nresults in " << Temp_out << " degrees " << UNITS_out<<" \n ";
return 0;
}</iostream.h>
Comment