In this challenge, write a program that takes in three arguments, a start temperature (in Celsius), an end temperature (in Celsius) and a step size. Print out a table that goes from the start temperature to the end temperature, in steps of the step size; you do not actually need to print the final end temperature if the step size does not exactly match. You should perform input validation: do not accept start temperatures less than a lower limit (which your code should specify as a constant) or higher than an upper limit (which your code should also specify). You should not allow a step size greater than the difference in temperatures. (This exercise was based on a problem from C Programming Language).
**THIS IS MY CODE**
#include<iostream>
using namespace std;
int main()
{
double celcius, farenhite;
int LOWER_LIMIT= 0;
int HIGHER_LIMIT= 5000;
int limitLow=-1, LimitHigh=0-1;
int step;
cout<<"How many steps are there?\n";
cin>>step;
for(int count=0; count<step; count++)
{
while(limitLow<LOWER_LIMIT || limitLow>10)
{
cout<<"Give me a lower limit that is greater than 0 and less than 10\n";
cin>>limitLow;
}
while(LimitHigh<10 || LimitHigh>HIGHER_LIMIT)
{
cout<<"Give me a higher limit greater than 10 and less than 5000\n";
cin>>LimitHigh;
}
cout<<"\nCelsius\t\tFahrenheit\n";
cout<<"\n-------\t\t----------\n";
celcius=limitLow;
celcius+=count;
farenhite=(celcius*9)/5+32;
cout<<"\n"<<celcius<<"\t\t"<<farenhite<<endl;
}
return 0;
}
OUTPUT:How many steps are there?
3
Give me a lower limit that is greater than 0 and less than 10
2
Give me a higher limit greater than 10 and less than 5000
23
Celsius Fahrenheit
------- ----------
2 35.6
Celsius Fahrenheit
------- ----------
3 37.4
Celsius Fahrenheit
------- ----------
4 39.2
Press any key to continue . . .
##I want the Celcius and Farenhite titles to show up once, what should I do to do that??##
I believe this is what your instructor is looking for here though.
define the constants up top. Also make sure to put .0 after all the numbers to make them float numbers. If you the compiler will think it's trying to add int to float and weird stuff will happen.
#include<iostream>
usingnamespace std;
#define LOWER_LIMIT 0.0 //Define lower and upper limit as constants
#define UPPER_LIMIT 5000.0
int main()
{
float celcius, fahrenheit;
float limitLow=-1.0, LimitHigh=9.0;
float step;
float i = 1.0;
cout<<"What is the size of the temperature step increase?\n";
cin>>step;
while(limitLow<LOWER_LIMIT || limitLow>10)
{
cout<<"Give me a lower limit that is greater than 0 and less than 10\n";
cin>>limitLow;
}
while(LimitHigh<10 || LimitHigh>UPPER_LIMIT)
{
cout<<"Give me a higher limit greater than or equal to 10 and less than 5000\n";
cin>>LimitHigh;
}
celcius = limitLow;
while (celcius < LimitHigh){
cout<<"\nCelsius\t\tFahrenheit\n";
cout<<"\n-------\t\t----------\n";
fahrenheit=((celcius*9.0)/5.0)+32.0;
cout<<"\n"<<celcius<<"\t\t"<<fahrenheit<<"\n";
celcius=limitLow + (step * i);
i = i + 1.0; //i'm not sure if i++ works with float
}
return 0;
}