fahr2-bug.c

/*
 ****** BUGGY VERSION *****
 *
 * FAHR2 -- program to print Fahrenheit temperatures between 0 and 300, 
 * counting by 20s, and the corresponding centigrade temperaures
 * It uses floating point numbers and a different control structure
 * than fahr1.c
 *
 * Usage: fahr2
 *
 * Inputs: none
 * Output: table of temperatures, as above
 * Exit Code: EXIT_SUCCESS (0) because all goes well
 *
 * Matt Bishop, Oct. 1, 2019
 *	original program written
 */
#include <stdio.h>
#include <stdlib.h>

/*
 * macros for constants
 */
#define LOWER		0		/* begin table here */
#define UPPER		300		/* end table here */
#define STEP		20		/* increment */

/*
 * print a table for Fahrenheit to Celsius
 * from 0 F to 300 F
 * floating point version
 */
int main(void)
{
	float fahr;			/* fahrenheit temperature */

	/*
	 * print out the lines for the table
	 */
	/* print the header */
	printf("deg F\t deg C\n");
	/* print the values */
	for(fahr = LOWER; fahr <= UPPER; fahr += STEP)
		printf("%3.0f\t%6.1f\n", fahr, (5/9) * (fahr - 32));

	/*
	 * say goodbye
	 */
	return(EXIT_SUCCESS);
}



UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 36A, Programming & Problem Solving
Version of April 2, 2024 at 12:13PM

You can get the raw source code here.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh