I cannot determine why the Celsius values in this code are producing rubbish values. (Look at second statement in the first for-loop).
CODE:
/* The program will output two columns with the temperature in degrees Fahrenhiet
and equivalent temperature in degrees Celcius. The range will be 0 to 300 farenhiet in
20 degree intervals. */
#include <stdio.h>
int main()
{
double fahr[20], cel[20]; // there should be 16 values (300/20 + 1) in these arrays and a null zero. (total of 17 values)
// Doesn't hurt to make them a bit larger than necessary (i.e. 20 instead of 17 values)
for (int i = 0; i < 16; i++)
{
fahr[i] = i*20; // Express Farhrenhiet as a linear function of i and iterate
cel[i] = (5 / 9) * (fahr[i] - 32); // Express Celcius as a linear function of fahr[i]
}
printf("Fahrenheit\tCelcius\n"); //printing the column headers
for (int j = 0; j < 16; j++)
{
printf("%.f", fahr[j]);
printf("\t\t%.2f", cel[j]);
printf("\n");
}
return 0;
}