Write a program that takes in 4 arguments a start temperatur

Write a program that takes in 4 arguments, a start temperature (in Celsius), an end temperature (in Celsius), a step size, and the number of decimal points to display. Print out a table that goes from the start temperature to the end temperature, in steps of the step size and calculates the corresponding temperature in Fahrenheit. You do not need to print the end temperature if it is outside the step size point. Your program must specify both an absolute upper and lower limit that are defined in the code as fixed values. You must perform input validation. The step size must be less than or equal to the difference in the temperatures the user inputs. Ask the user for how many decimal points to display. Use field width definitions we discussed in class to define the table. The 4 user inputs should be defined as type int Please enter a lower temperature limit, min. Temp. (C) >= 0: 10 Please enter an upper temperature limit, 10

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

*/

 Write a program that takes in 4 arguments, a start temperature (in Celsius), an end temperature (in Celsius), a step size, and the number of decimal points to
 Write a program that takes in 4 arguments, a start temperature (in Celsius), an end temperature (in Celsius), a step size, and the number of decimal points to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site