Code:
#include <stdio.h>
#include <string.h>
#define MAX 20
void Greetings(void);
void getchoice(void);
void cmenu(void);
void ftoc(double temp, char name);
void ctof(double temp, char name);
void ftoK(double temp, char name);
void ctoK(double temp, char name);
void Ktof(double temp, char name);
void Ktoc(double temp, char name);
void displayresult(double Ctemp, double temp, char name);
int main(void)
{
Greetings();
getchoice();
return (0);
}
void Greetings(void)
{
printf("Hello, this program displays menu options for temperature conversions\n");
printf("of Fahrenheit, Celsius, and Kelvin.\n\n\n");
}
void getchoice(void)
{
char ch;
char *name[MAX];
printf(" Main Menu \n");
printf("------------------------------\n");
printf("a. Temperature Conversion\n");
printf("q. Quit the program\n");
printf("Enter the letter of your choice:\n");
scanf("%c", &ch);
if (ch == 'a')
{
printf("Hi, please enter your first name.\n");
scanf("%s", &name);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
cmenu();
}
else (ch == 'q');
printf("Goodbye!\n");
}
void cmenu(void)
{
int choice;
double temp;
char name;
while (choice != 7)
{
printf(" Conversion Menu \n");
printf("------------------------------\n");
printf("1. Fahrenheit to Celsius\n");
printf("2. Celsius to Fahrenheit\n");
printf("3. Fahrenheit to Kelvin\n");
printf("4. Celsius to Kelvin\n");
printf("5. Kelvin to Fahrenheit\n");
printf("6. Kelvin to Celsius\n");
printf("7. Main Menu\n");
printf("Enter the number of your choice:");
scanf("%d", &choice);
switch (choice)
{
case 1 : ftoc(temp, name);
break;
case 2 : ctof(temp, name);
break;
case 3 : ftoK(temp, name);
break;
case 4 : ctoK(temp, name);
break;
case 5 : Ktof(temp, name);
break;
case 6 : Ktoc(temp, name);
break;
case 7 : getchoice();
break;
}
}
}
void getdata(double *temp)
{
printf("Please enter your temperature to be converted:\n");
scanf("%lf", temp);
}
void ftoc(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = (temp * 1.8) + 32;
displayresult(Ctemp, temp, &name);
}
void ctof(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = (temp - 32) / 1.8;
displayresult(Ctemp, temp, &name);
}
void ftoK(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = ((temp * 1.8) + 32) +273.15;
displayresult(Ctemp, temp, &name);
}
void ctoK(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = temp + 273.15;
displayresult(Ctemp, temp, &name);
}
void Ktof(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = ((temp - 273.15) * 1.8) + 32;
displayresult(Ctemp, temp, &name);
}
void Ktoc(double temp, char name)
{
double Ctemp;
getdata(&temp);
Ctemp = temp - 273.15;
displayresult(Ctemp, temp, &name);
}
void displayresult(double Ctemp, double temp, char name)
{
printf("%s's Conversions:\n\n", &name);
printf("Original temperature was %.1lf and converted temperature is %.1lf.\n\n", temp, Ctemp);
}