I am learning about functions, and so I would like your criticism (if there is anything wrong with the way I did things) - the program works, but that does not mean its right....pragmatism is not so good sometimes.....
Code:
#include <stdio.h>
float convert( float fahr_to_func );
/* fahr_func.c - kermit - August 20, 2003
* (another exercise from K & R)
* print Fahrenheit to Celsius table
* for fahr = 0, 20, ..., 300
* This version uses a function for the conversion
*/
int main(void)
{
float fahr;
float fahr_to_func;
#define LOWER 0 /* lower limit of temperature table */
#define UPPER 300 /* upper limit of temperature table */
#define STEP 20 /* step size */
printf( "\n" );
printf( "\t\t+------------------------------------------------+\n" );
printf( "\t\t| |\n" );
printf( "\t\t| Fahrenheit to Celsius Conversion Table |\n" );
printf( "\t\t| |\n" );
printf( "\t\t+------------------------------------------------+\n\n" );
for ( fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP )
{
fahr_to_func = fahr;
printf( "\t\t\t\t%3.0f\t%6.1f\n", fahr, convert( fahr_to_func ));
}
printf( "\n" );
return 0;
}
/* convert; convert Fahrenheit to Celsius */
float convert( float fahr )
{
float celsius;
celsius = ( 5.0 / 9.0 ) * ( fahr - 32.0 );
return celsius;
}
try and be nice
kermit