Question: Can you tell me what is wrong with this code? I'm trying to convert from fahrenheit to celsius reading from format input: first temp in
Can you tell me what is wrong with this code? I'm trying to convert from fahrenheit to celsius reading from format input: first temp in fahrenheit, last temp in farenheit, increment value. Stop when the first temp is larger than the last temp.
#include
#include
#include
using namespace std;
void input(double firstFah, double lastFah, double incrementValue);
double convert(double firstFah, double lastFah, double celsius, double incermentValue);
void output(double firstFah, double celsius);
int main()
{
int first=0;
int last=0;
int incre=0;
int celsius=0;
input(first, last, incre);
cin >> first >> last >> incre;
convert(first, last, celsius, incre);
output(first, celsius);
cout << first << " " << celsius;
return 0;
}//end main
void input(double, double, double) {
double firstFah=0;
double lastFah=0;
double incrementValue=0;
cout << "Enter three values as following: first temperature in fahrenheit, last temperature in fahrenheit," <<
"increment value" << endl;
cin >> firstFah >> lastFah >> incrementValue;
if (firstFah > lastFah)
cout << "Invalid value, please re-enter" << endl;
cin >> firstFah >> lastFah >> incrementValue;
}//end input
double convert(double, double, double, double) {
double firstFah = 0;
double lastFah=0;
double celsius=0;
double incrementValue=0;
while (firstFah <= lastFah) {
celsius = (firstFah - 32) * 5 / 9;
//cout << fixed << setprecision(5) << firstFah << " " << celsius << endl;
firstFah = firstFah + incrementValue;
}
return firstFah;
}//end convert
void output(double, double) {
double firstFah=0, celsius=0;
cout << fixed << setprecision(5) << firstFah << " " << celsius << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
