temperature convertion

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??##

Anything inside your for loop will get processed until your for loop exits. And you have some logic issues.

Here is a starting approach for you hope it helps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<iomanip>

const double LOWER_LIMIT = 0.0, HIGHER_LIMIT = 5000.0;

int main()
{
	double celsius, fahrenheit, lowLimit, highLimit, stepSize;
	int step;
	
	//Code Here, Ask User for input
	while (lowLimit < LOWER_LIMIT){//validate
		//Code Here, Ask again if invalid
		}
	

	//Code Here, Ask User for input
	while (highLimit < lowLimit || highLimit > HIGHER_LIMIT){//validate
		//Code Here, Ask again if invalid
	}

	//Code Here, Ask User for input
	while (step > highLimit - lowLimit){//validate
		//Code Here, Ask again if invalid
	}

	std::cout << "\nCelsius\t\tFahrenheit\n";
	std::cout << "\n-------\t\t----------\n";
	
	stepSize = (highLimit - lowLimit) / (double)step;//Set increment
	celsius = lowLimit;//Set condition
	while(celsius < highLimit){//validate
		//Cout Code Here
		celsius += stepSize;//increment
	}
	return 0;
}
Try to use the code tags when posting please.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
using namespace 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;
}
thanks, it worked :D
Topic archived. No new replies allowed.