In both of my functions the the correct temperature is calculated, which is proven by the printf line, but when it is returned the result always equals 3.
#include <stdio.h>
#include <stdlib.h>
main() {
int choice = 0;
int fahrenheit = 0;
int celsius = 0;
printf("Choose from the following:\nEnter 1 to convert from fahrenheit to celsius");
printf("\nEnter 2 to convert from celsius to fahrenheit\nEnter 3 to quit");
printf("\nType your choice here: ");
scanf_s("%i", &choice);
switch (choice) {
case 1:
printf("\nYou choose fahrenheit to celsius\n");
printf("Enter a temperature in fahrenheit: ");
scanf_s("%i", &fahrenheit);
celsius = fahrenheittocelsius(fahrenheit);
printf("\n%i degrees fahrenheit equals %i degrees celsius\n\n", fahrenheit, celsius);
break;
case 2:
printf("\nYou choose celsius to fahrenheit\n");
printf("Enter a temperature in celsius: ");
scanf_s("%i", &celsius);
fahrenheit = celsiustofahrenheit(celsius);
printf("\n%i degrees celsius equals %i degrees fahrenheit\n\n", celsius, fahrenheit);
break;
case 3:
printf("\ncongratulations you have gained nothing\n");
break;
}
system("pause");
}
float fahrenheittocelsius(int f){
int result;
result = (f - 32.0) * (5.0/9.0);
printf("%i\n", result);
return result;
}
float celsiustofahrenheit(int c) {
int result;
result = (9.0 / 5.0) * c + 32.0;
printf("%i\n", result);
return result;
}