I am doing a Udemy C course and some doubts have arisen regarding the functions in C. One of the exercises it's about temperature conversion (celsius, F and K) using functions and when my first thought was that:
void CF(){
float temp1, temp2;
printf("Escribe que temperatura quieres convertir a Fahrenheit: ");
scanf("%f", &temp1);
temp2 = (temp1 * 1.8) + 32;
printf("La temperatura en Fahrenheit es: %f", temp2);
}
But the solved exercise uses:
float fahrenheit(float C){
float F=0;
F = (9*C)/5 + 32;
return F;
}
And entering data through "int main" program while I introduce through the function.
My questions are: - It's better to introduce data through int main code or the function? - Why he uses "Float" function and I use "void" function and works fine in both cases?
Anyway, my code works, but I want to know what is better and why.
Thanks in advance and forgive me for my english.