Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program which converts temperature degrees between Fahrenheit (F) and Ce

ID: 3685315 • Letter: W

Question

Write a program which converts temperature degrees between Fahrenheit (F) and Celsius (C) in both directions. Formula are:

From F to C -- C = (F - 32) / 1.8
From C to F -- F = 1.8 * C + 32

Your program must do the following.

Name the source file as "Temperature.cpp".

Allow the user to enter either/both scale, and display the equivalent temperature degree in the other scale. For example, if the user enters "16.0 C", your program should output "60.8 F", while if the user enters "56.2 F", your program outputs "13.4 C".

Accept both upper and lower case character for the scale, that is, F or f and C or c.

Display the result with decimal precision 1.

Write the following functions to do some of tasks involved in the program, and main() MUST call those functions appropriately to pull together the whole program.

double toCels(double t );
This function receives a temperature degree (passed in as the parameter t) which is assumed to be in Fahrenheit, and returns the degree which is the equivalent degree in Celsius.
  

double toFahren(double t);

This function converts a temperature degree (passed in as the parameter t) which is assumed to be in Celsius, and returns the degree which is the equivalent degree in Fahrenheit.

int findScaleCase(char s);
This function receives the scale character (e.g. 'F') as the parameter, and returns an integer -- 0 if is 'F' or 'f', or 1 if it is any other character (and treat/pretend it as the case for Celsius) . Then main() receives the returned case integer, and calls the toCels() or toFahren() function to obtain the equivalent temperature degree.

Here are a couple of sample sessions:

Explanation / Answer

#include <cstdio>
#include <iostream>

using namespace std;

int main()
{

int choice;
float ctemp,ftemp;
cout << "1.Celsius to Fahrenheit" << endl;
cout << "2.Fahrenheit to Celsius" << endl;
cout << "Choose between 1 & 2 : " << endl;
cin>>choice;
if (choice==1)
{
cout << "Enter the temperature in Celsius : " << endl;
cin>>ctemp;
cout << "Entered temperature to convert : " << ctemp << " cel" << endl;
ftemp=(1.8*ctemp)+32;
cout << "Temperature in Fahrenheit = " << ftemp << " fah" << endl;
}
else if (choice==2)
{
cout << "Enter the temperature in Fahrenheit : " << endl;
cin>>ftemp;
cout << "Entered temperature to convert : " << ftemp << " fah" << endl;
ctemp=(ftemp-32)/1.8;
cout << "Temperature in Celsius = " << ctemp << " cel" << endl;
}
else
if ( choice != 1 || choice!=2)
{cout << "Invalid Input" << endl;}
return 0;
}
      
      
       

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote