Originally Posted by
fredlo2010
The reason why I have four columns in my table is because the assignment is like that; which also explains why I am using "temp"; the question is not about converting from unit the other. It's just go through a range of numbers assuming that is Fahrenheit and convert to Celsius; and then do the same assuming its Celsius. (it's a little weird but I am replicating the output of the assignment to the letter
)
Ah, I see what you're trying to do there. Something still isn't lining up, though.
Code:
printf("\nFahrenheit\tCelsius\t\tFahrenheit\tCelsius\n");
printf("%8.1f\t%6.1f\t%15.1f\t%14.1f\n",temp,celsius,temp,fahr);
The fourth column header says "Celsius", but the fourth argument you're printing is "fahr". You should ensure that your variables contain values that match the name (i.e. "fahr" should not contain a value in Celsius).
I don't think it makes much sense to convert from some unitless value to a temperature. I would suggest following my original advice and using "fahr" in lieu of "temp". Then use this value to find Celsius (celsius = convertToCelsius(fahr)). Then use the new value of "celsius" to convert back to Fahrenheit (3 columns total). This is also a good way to visually confirm the conversions (columns 1 and 3 would be basically the same value). This way just makes more sense to me, but you can approach it however you'd like.
Originally Posted by
fredlo2010
Also I added named constants to the validation.
Very good. However, the idea of using named constants is so, if you want to change all of those values in the program, you just have to change the #define. Therefore, I would change this:
Code:
printf("\nInvalid input, make sure you are entering a single digit number 1 - 9\n");
... to this:
Code:
printf("\nInvalid input, make sure you are entering a single digit number %d - %d\n", VALID_INPUT_MIN, VALID_INPUT_MAX);
Originally Posted by
fredlo2010
I am using floats because that's what has been used so far in my book; no reason in specific. Perhaps I am moved by the "%f" in the printf() so I can associate a little
"%f" in "printf()" is used for floats and doubles. But floats are fine.
If you really want to be explicit, you can declare your constants as floats by appending with an 'f':
#define TEMP_MAX 280.0f
float fahr = 0.0f;
etc
Originally Posted by
fredlo2010
Thanks a lot for your help again. This is the final reviewed code.
You're very welcome.