I am trying to combine Switch into Void Function to convert Celsius to Fahrenheit and vice versa. I am not sure what is correct way to combine Switch and Void Function together. My code is at below. Any advice is valuable for me. Thank you.
#include<stdio.h>
void fahtocel(void);
void celtofah(void);
int main(void)
{
int tem;
printf("Please select your choice\n");
printf("Enter 1 if you need to convert Fahrenheit to Celsius\n");
printf("Enter 2 if you need to convert Celsius to Fahrenheit\n");
scanf("%d", &tem);
switch(tem) {
case 1:
fahtocel();
break;
case 2:
celtofah();
break;
}
return 0;
}
void fahtocel()
{
float fahr;
printf("Please input Fahrenheit: ");
scanf("%2.f", &fahr);
printf("%3f Fahrenheit is equal %3.0f Celsius \n",fahr,(5.0/9.0)*(fahr - 32)*5/9;
}
void celtofah()
{
float celsius;
printf("Please input celsius: ");
scanf("%2.f", &celsius);
printf("%2.f Celsius is equal %2.f Fahrenheit\n",celsius, (9*celsius/5)+32);
}