Code:
/*Lab 7*/
#include <stdio.h>
greet();
calc();
display();
/*The first function is used to declare the variables being used in the program.
It also states the three other functions used in this program, and initiates them.*/
int main()
{
//Input variables
greet();
calc();
display();
return 0;
}
/*This function is used to prompt the user to input their values so calculations can begin*/
greet()
{
float fahr1, fahr2, fahr3, fahr4;
//Put a heading to explain what the program is used for
printf("This program is designed to convert a given degree in farenheit to celsius. This");
printf("program is also used to find out how many degrees away the entered degree is "
"from it's freezing point in both farenheit and celsius\n\n\n");
//Assign values to variables
printf("Type your first degree in Farenheit: ");
scanf("%f", &fahr1);
printf("\n\nType your second degree in Farenheit: ");
scanf("%f", &fahr2);
printf("\n\nType your third degree in Farenheit: ");
scanf("%f", &fahr3);
printf("\n\nType your fourth degree in Farenheit: ");
scanf("%f", &fahr4);
printf("\n\n\n\n");
calc(fahr1, fahr2, fahr3, fahr4);
display(fahr1, fahr2, fahr3, fahr4);
}
/*This next function will be used to carry out the calculations and work out the coversions*/
calc(fahr1, fahr2, fahr3, fahr4)
{
float cel1, cel2, cel3, cel4, diffahr1, diffahr2, diffahr3, diffahr4;
//Use equation (5.0/9.0)*(Fahrenheit-32) to convert to celsius
cel1= (5.0/9.0)*(fahr1-32);
cel2= (5.0/9.0)*(fahr2-32);
cel3= (5.0/9.0)*(fahr3-32);
cel4= (5.0/9.0)*(fahr4-32);
//Farenheit to freezing point distance
diffahr1= fahr1-32;
diffahr2= fahr2-32;
diffahr3= fahr3-32;
diffahr4= fahr4-32;
display(cel1, cel2, cel3, cel4, diffahr1, diffahr2, diffahr3, diffahr4);
}
/* This function is used to simply display all of the calculations done above.*/
display(fahr1, fahr2, fahr3, fahr4, cel1, cel2, cel3, cel4, diffahr1, diffahr2, diffahr3, diffahr4)
{
/*Table which displays the farenheit degrees entered, their conversions to celsius,
and the amount of degrees from freezing for both celsius and farenheit */
printf("Number Farenheit Celsius Freezing-Fahrenheit Freezing-Celsius\n");
printf("_______________________________________________________________________________\n");
printf("1 %f %f %f %f \n", fahr1, cel1, diffahr1, cel1);
printf("2 %f %f %f %f \n", fahr2, cel2, diffahr2, cel2);
printf("3 %f %f %f %f \n", fahr3, cel3, diffahr3, cel3);
printf("3 %f %f %f %f \n", fahr4, cel4, diffahr4, cel4);
}