where is the value of variable"fahr"?
The function only accepts the value of variable "step" passed to it. Therefore the function has undefined values and didn't work.
As a note you should use double instead of int for the temperature variables in case you wont get any wrong answers.
Dont use while loop here. A for loop makes clear. And you are wrongly defining unnecessary types like float fahr, it would take infinite loop like starting from 0>0.00001>0.00002(like this)so use only int for both while and for loops. Hope you are ok :)
#include<iostream>
// no using namespace; there is exactly one identifier that we will use, once
double x( int tempF ) // our loop will supply integers
{
return (tempF-32) * 5.0 / 9.0;
}
int main()
{
// named constants make code more clear
constexprint Upper {300};
constexprint Step {20}
int fahr {0};
for ( ; fahr <= Upper; fahr += Step )
{
std::cout << fahr << '\t' << x( fahr ) << '\n';
}
return 0;
}
There is nothing wrong in using while, but the loop counter is indeed best kept as integral value. You can always convert/cast integer to float, if needed.
When you have fahr<=upper, where fahr is float and upper is int, the operator<= must cast the upper to float. Likewise for the fahr+step. The Fahrenheit temparatures are clearly integer values, so why not keep them as such?