farenheit to celsius (very old code)

Most measurements in the care sheets are given in inches and Farenheit,

because the author lives in the still non-metric USA. The author has

been asked several times, whether she could provide metric data.

She doesn't currently have the time to go through all the pages and add metric

measurements. However, she can provide the following little C program that

she uses herself to do conversions.

This program was originally written and compiled on a Solaris machine

using CC and run in a shelltool.

/* Aleks Haecky, August 28, 1989 */

#include <stdio.h>

/****************************************************************************/

/* Print the command line menu and read a character. */

/****************************************************************************/

char menu()

{

printf("\nSelect a conversion and enter the number:\n\n");

printf("\t1: Fahrenheit -> Celsius\n");

printf("\t2: Celsius -> Fahrenheit\n");

printf("\t3: Pounds -> Kilograms\n");

printf("\t4: Kilograms -> Pounds\n");

printf("\t5: 1 oz gold -> 1 kg gold\n");

printf("\t6: feet -> meters\n");

printf("\tq: quit program\n");

printf("\n\t=> ");

return(getchar());

}

/****************************************************************************/

/* Read a floating point number from the terminal */

/****************************************************************************/

float readnumber()

{

float f;

printf("\nEnter the number to convert: ");

scanf("%f", &f);

return(f);

}

/****************************************************************************/

/* Loop until q is entered and convert the numbers according to selection */

/****************************************************************************/

main ()

{

char selection; /* selected operation */

float number; /* entered and converted number */

/* enter the conversion you want */

while ((selection = menu()) != 'q') {

if (selection == '1' || selection == '2' ||

selection == '3' || selection == '4' ||

selection == '5' || selection == '6' ) {

number = readnumber();

/* calculate the result: */

switch (selection) {

case '1':

number = (number - 32.0) * 5.0 / 9.0;

printf("\nCelsius: %6.3f\n", number);

break;

case '2':

number = number * 9.0 / 5.0 + 32.0;

printf("\nFarenheit: %6.3f\n", number);

break;

case '3':

number = number * 0.454;

printf("\nPounds: %6.3f\n", number);

break;

case '4':

number = number / 0.454;

printf("\nKilograms: %6.3f\n", number);

break;

case '5':

number = 1000.0 / (454.0/16) * number;

printf("\nYour gold is worth: %6.2f dollars\n", number);

break;

case '6':

number = number * 0.32;

printf("\nMeters: %6.3f\n", number);

break;

default:

break;

}

}

else printf("\n\nERROR: Invalid selection - try again:");

getchar (); /* clean up a <return> that's left on ?? */

}

}