Write a program that takes in 4 arguments a start temperatur
Solution
// C++ code celsius to Fahrenheit
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
int lower_temperature, upper_temperature;
int step, decimal_places;
// input validation
while(true)
{
cout << \"Please enter a lower temperature limit, Min. Temp.(C)>= 0: \";
cin >> lower_temperature;
if(lower_temperature >= 0)
break;
else
cout << \"Invalid Input\ \";
}
while(true)
{
cout << \"Please enter an upper temperature, 10 < Max,Temp.(C) <= 300: \";
cin >> upper_temperature;
if(upper_temperature > 10 && upper_temperature <= 300)
break;
else
cout << \"Invalid Input\ \";
}
while(true)
{
cout << \"Please enter a step, 0 < step <= 10: \";
cin >> step;
if(step > 0 && step <= 10 && step <= (upper_temperature- lower_temperature ))
break;
else
cout << \"Invalid Input\ \";
}
cout << \"Please enter the number of decimal points to display: \";
cin >> decimal_places;
cout << \"\ Celsius\\t\\tFahrenheit\ \";
cout << \"--------------------------------\ \";
for (double i = lower_temperature; i <= upper_temperature; i= i+step)
{
std::cout << std::fixed;
std::cout << std::setprecision(decimal_places);
double fahrenheit = (i*9.0)/5.0 + 32.0;
cout << setprecision(decimal_places) <<i << \"\\t\\t\" << fahrenheit << endl;
}
return 0;
}
/*
output:
Please enter a lower temperature limit, Min. Temp.(C)>= 0: -4
Invalid Input
Please enter a lower temperature limit, Min. Temp.(C)>= 0: 10
Please enter an upper temperature, 10 < Max,Temp.(C) <= 300: 304
Invalid Input
Please enter an upper temperature, 10 < Max,Temp.(C) <= 300: 20
Please enter a step, 0 < step <= 10: 12
Invalid Input
Please enter a step, 0 < step <= 10: 4
Please enter the number of decimal points to display: 6
Celsius Fahrenheit
--------------------------------
10.000000 50.000000
14.000000 57.200000
18.000000 64.400000
*/

