Question

In: Computer Science

Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

Temperature Converter

Create a temperature conversion program that will convert the following to Fahrenheit:

Celsius
Kelvin
Newton
Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification:

C - Celsius
K - Kelvin
N - Newton
In addition your program should take in the following character to exit the program:

X - eXit the program

The numeric input for your program should be of type double. The program will continue to input and convert temperatures until the 'X' character is input for the conversion type.

Your input should be in the following form:

60 C

This would convert the 60 degrees Celsius to Fahrenheit and should output a value of 140

The following equations can be used to convert the different temperature types to Fahrenheit:

Kelvin - F = (K - 273.15) * 1.8000 + 32

Celsius - F = C * 9/5 + 32

Newton - F = N * 60 / 11 + 32


Required:

You are not allowed to use a do-while loop for this program.

Use a while loop in conjunction with a switch statement. Please review the information on primed loops.

You must prime your loop with input from the keyboard before the while loop starts.

The program should continue converting temperatures until X is entered as a conversion type.

C++

Solutions

Expert Solution

C++ Code:

#include <iostream>

#include<stdlib.h>

using namespace std;

double FtoK(double f){

return (f - 32) * (5/9) + 273.15;

}

double FtoC(double f){

return ((f - 32) * 0.55);

}

double FtoN(double f){

return ((f - 32)*(0.18333));

}

int main() {

char sel='\0';

double temp;

while(sel!='X' || sel!='x'){

cout<<"C: Fahrenheit to celcius\nK: Fahrenheit to Kelvin\nN: Fahrenheit to Newton\nX: Exit"<<endl;

cin>>sel;

switch(sel){

case 'C':

case 'c':

double res;

cout<<"Enter temprature in Fahrenheit: ";

cin>>temp;

res=FtoC(temp);

cout<<temp<<" F = "<<res<<" C"<<endl;

break;

case 'K':

case 'k':

double res1;

cout<<"Enter temprature in Fahrenheit: ";

cin>>temp;

res1=FtoK(temp);

cout<<temp<<" F = "<<res1<<" K"<<endl;

break;

case 'N':

case 'n':

double res2;

cout<<"Enter temprature in Fahrenheit: ";

cin>>temp;

res2=FtoN(temp);

cout<<temp<<" F = "<<res2<<" N"<<endl;

break;

case 'X':

case 'x':

exit(0);

default:

cout<<"Wrong input"<<endl;

}

}

}

if you like the answer please provide a thumbs up.


Related Solutions

Temperature Conversion Menu (100 pts) The three common temperature scales are Celsius, Fahrenheit and Kelvin. The...
Temperature Conversion Menu (100 pts) The three common temperature scales are Celsius, Fahrenheit and Kelvin. The conversion formulae for each of the scales is shown below (where °C, °F and K represent the temperatures in degrees Celsius, degrees Fahrenheit and Kelvin respectively): Celsius to Fahrenheit: °F = (9.0/5) ´ (°C) + 32 Celsius to Kelvin: K = °C + 273.15 Kelvin to Celsius: °C = K – 273.15 Kelvin to Fahrenheit: °F = (9.0/5) ´ (K – 273.15) + 32...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.  
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
(Python) Write a code converting degrees in Fahrenheit to degrees Kelvin, using this conversion equation conversion...
(Python) Write a code converting degrees in Fahrenheit to degrees Kelvin, using this conversion equation conversion from degrees Fahrenheit to Celcius: ? = (? − 32) x 5/9 and then to degrees Kelvin: ? = ? + 273.15 with the following properties 1) the code should take into account that temperature in degrees Kelvin cannot be smaller than zero. In other words, your code should return 0 Kelvin as the smallest temperature for any input value of degrees Fahrenheit). 2)...
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user...
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:    F = (9 / 5) * C + 32 Create integer constants for the 3 numbers in the formula (9, 5, and 32).  Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a...
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
7.14 LAB: Temperature conversion In this lab, you will implement a temperature converter. Five UI elements...
7.14 LAB: Temperature conversion In this lab, you will implement a temperature converter. Five UI elements are declared for you in the template: Element's ID Element description cInput Text input field for Celsius temperature fInput Text input field for Fahrenheit temperature convertButton Button that, when clicked, converts from one temperature to the other errorMessage Div for displaying an error message when temperature cannot be converted weatherImage Image corresponding to the temperature Implement the conversion functions (2 points) Implement the convertCtoF()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT