Write a program that uses functions to provide information about the perceived t
ID: 3546160 • Letter: W
Question
Write a program that uses functions to provide information about the perceived
temperature. For all of the functions, be sure to the function declarations before main, but the
function definitions after main.
The program should allow users to enter the temperature in either Fahrenheit or Celsius and then
give output in, Fahrenheit and Celsius as well as information on the wind-chill and the heat index
when it is relevant.
1. A function called welcome that returns nothing and takes no parameters. When called the
function should print to the screen the message: Welcome to Weather Advisory.
2. Write a function that converts temperature from Celsius to Fahrenheit using the relationship F =
1.8C + 32.0 and returns the converted value to the main program as a real number. That is, the
input to the function is the Celsius temperature; and the returned output is a double (Fahrenheit
temperature).
3. Write a different function that converts temperature from Fahrenheit to Celsius and returns the
converted value to the main program as a real number. That is, the input to the function is the
Fahrenheit temperature; and the returned output is a double (Celsius temperature). Use the
relationship C = (F
Explanation / Answer
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
void welcome();
double convertCelsiusToFharenheit(double c) ;
double convertFarenheitToCelsius(double f) ;
double calculateWindChill(int temprature);
bool isInvalidInput() ;
double userInput() ;
int main() {
welcome();
double farenheit , celsius;
char choice;
cout<<"What kind of temprature you want to input ";
cout<<"f or F (farenheit) ";
cout<<"c or C (celsius) ";
while(1) {
cout<<"your choice:";
cin>>choice;
if(choice == 'c' || choice == 'C' || choice == 'f' || choice =='F' ) {
break;
} else {
cout<<"Enter a value f or F or c or C ";
}
}
if(choice == 'c' || choice == 'C') {
celsius = userInput();
farenheit = convertCelsiusToFharenheit(celsius);
} else {
farenheit = userInput();
celsius = convertFarenheitToCelsius(farenheit);
}
cout<<fixed;
cout<<setprecision(2);
cout<<"celsius : "<<celsius<<endl;
cout<<"Farenheit : "<<farenheit<<endl;
if(farenheit < 50 ) {
cout<<"wind chill: "<<calculateWindChill(farenheit)<<" F"<<endl;
}
return 0;
}
void welcome() {
cout<<" Welcome to Weather Advisory ";
}
double convertCelsiusToFharenheit(double c) {
double f = 1.8*c+32.0;
return f;
}
double convertFarenheitToCelsius(double f) {
double c = (f - 32.0)/1.8;
return c;
}
bool isInvalidInput() {
if(!cin) {
cin.clear();
cin.ignore (1000, ' ');
return true;
}
return false;
}
double userInput() {
double temprature;
while(1) {
cout<<"Enter the temprature (real number ie. double or float) ";
cin>>temprature;
if(isInvalidInput()) {
cout<<"Wrong Input :-Enter a real value (double or float) ";
} else {
break;
}
}
return temprature;
}
double calculateWindChill(int temprature) {
double windSpeed;
cout<<"Enter the wind speed ";
cin>>windSpeed;
double windChill = 35.74 + (0.6215*temprature) - 35.75* pow(windSpeed, 0.16)+ 0.4275 * temprature * pow(windSpeed,0.16 );
return windChill;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.