//********************************************************
//
// C Midterm - Question 7
//
// Name: Maya Mahin
//
// Class: C Programming, Spring 2025
//
// Date: March 23, 2025
//
// Description: Program which facilitates the conversion of fahrenheit to
// celsius temperatures and vice versa
//
//********************************************************
#include <stdio.h>
float toCelsius(float fahrenheitTemp);
float toFahrenheit(float celsiusTemp);
void printTableHeader(int tableNum);
void printTable(int TableNum, float temperature1, float temperature2);
int main(void) {
printTableHeader(1);
for (int i=0; i<101; i++) {
float fahrenheitRetVal=toFahrenheit(i);
printTable(1,i,fahrenheitRetVal);
}
printTableHeader(2);
for (int i=32; i<213; i++) {
float celsiusRetVal=toCelsius(i);
printTable(2,i,celsiusRetVal);
}
return 0;
}
//**************************************************************
// Function: toCelsius
//
// Purpose: Receives a temperature in fahrenheit, converts it
// to Celsius and returns the converted value
//
// Parameters:
//
// temp - input temperature in fahrenheit
//
// Returns: temp_convert - input temperature in celsius
//
//**************************************************************
float toCelsius(float fahrenheitTemp){
float celsiusTemp=(fahrenheitTemp - 32) * 5/9;
return celsiusTemp;
}
//**************************************************************
// Function: toFahrenheit
//
// Purpose: Receives a temperature in celsius, converts it
// to Fahrenheit and returns the converted value
//
// Parameters:
//
// temp - input temperature in celsius
//
// Returns: temp_convert - input temperature in fahrenheit
//
//**************************************************************
float toFahrenheit(float celsiusTemp){
float fahrenheitTemp=(celsiusTemp * 9/5) + 32;
return fahrenheitTemp;
}
//**************************************************************
// Function: printTableHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printTableHeader (int tableNum)
{
if (tableNum==1){
// print the table header
printf("\nCelsius Fahrenheit\n"); printf("------------------------\n"); }
else if (tableNum==2){
// print the table header
printf("\nFahrenheit Celsius\n"); printf("-----------------------\n"); }
} // printHeader
//*************************************************************
// Function: printTable
//
// Purpose: Prints out all the temperature information
// in a nice and orderly table format.
//
//*************************************************************
void printTable (int tableNum, float temperature1, float temperature2)
{
// print the temperature
if (tableNum==1){
temperature1, temperature2);
}
else if (tableNum==2){
temperature1, temperature2);
}
}