Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 20
void clearScreen();
void greetings(void);
void getchoice(void);
void cmenu(char *name);
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);
int totalCount(int count1, int count2, int count3, int count4, int count5, int count6);
void displayresult(double Ctemp, double temp, char *name);
int main(void)
{
int count1, count2, count3, count4, count5, count6, Tcount;
FILE *otpt;
otpt = fopen("tmpstats.txt", "w");
greetings();
getchoice();
totalCount(count1, count2, count3, count4, count5, count6);
fprintf(otpt, "%d", Tcount);
fclose(otpt);
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)
{
int num;
char name[MAX];
printf(" Main Menu \n");
printf("------------------------------\n\n");
printf("Enter the number of your choice:\n\n");
printf("1. Temperature Conversion\n");
printf("2. Quit the program\n\n");
printf("Choice: ");
scanf("%d", &num);
if (num == 1)
{
printf("Hi, please enter your first name.\n");
scanf("%s", name);
clearScreen();
cmenu(name);
}
else if(num == 2);
clearScreen();
printf("Goodbye!\n");
}
void clearScreen()
{
system("cls");
}
void cmenu(char *name)
{
int Choice;
int *count1, *count2, *count3, *count4, *count5, *count6;
double temp;
while (Choice != 7)
{
printf(" Conversion Menu \n");
printf("------------------------------\n");
printf("Enter the number of your choice:\n\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\n");
printf("Choice: ");
scanf("%d", &Choice);
switch (Choice)
{
case 1 : count1 =0;
ftoc(temp, name);
count1++;
break;
case 2 : count2 =0;
ctof(temp, name);
count2++;
break;
case 3 : count3 =0;
ftoK(temp, name);
count3++;
break;
case 4 : count4 =0;
ctoK(temp, name);
count4++;
break;
case 5 : count5 =0;
Ktof(temp, name);
count5++;
break;
case 6 : count6 =0;
Ktoc(temp, name);
count6++;
break;
case 7 : clearScreen();
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 - 32) / 1.8;
displayresult(Ctemp, temp, name);
}
void ctof(double temp, char *name)
{
double Ctemp;
getdata(&temp);
Ctemp = (temp * 1.8) + 32;
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);
}
int totalCount(int count1, int count2, int count3, int count4, int count5, int count6)
{
int Tcount;
Tcount = count1 + count2 + count3 + count4 + count5 + count6;
return Tcount;
}
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);
}