Temperature conversion in C I have started to learn C and I have tried my hand at temperature conversion. The idea is to convert a temperature from Fahrenheit to Celsius and vice/versa. Can somebody review my code and let me know how I might be able to improve it?  My program is as follows:

#include &lt;stdio.h&gt;


void fahconv()
{
    double fah;
    puts("Enter value to convert from Fahrenheit to Celsius");
    scanf("%lf",&amp;fah);
    printf("Converted temperature from F to C: %lf",((fah - 32.0)*5.0)/9.0);
}

void celsconv()
{
    double cels;
    puts("Enter value to convert from Celsius to Fahrenheit");
    scanf("%lf",&amp;cels);
    printf("Converted temperature from C to F: %lf",(cels*9/5)+32);
}

void invalidchoice()
{
    printf("Invalid choice..exiting");
}

int main()
{
    char choice;
    puts("Enter (F or f) to convert from Fahrenheit to Celsius");
    puts("Enter (C or c) to convert from Celsius to Fahrenheit \n");
    scanf("%c",&amp;choice);
    switch(choice)
    {
        case 'c': 
        case 'C': celsconv();
              break;
        case 'f': 
        case 'F': fahconv();
              break;
        default: invalidchoice();
    }
    return 0;
}
You don't need invalidchoice() as it just prints a statement and nothing else.  Just put the printf() under default.
Consider receiving all user input in main() and having the functions only do the calculations.  It's best to have a function do one (useful) thing.

In this form, the functions could also return the values to main() and displayed.  With the user input eliminated, they should now take the original temperature as an argument.
Optionally, you can return EXIT_SUCCESS or EXIT_FAILURE instead of 0 or 1, respectively.  It's especially important to return a failure value if the conversion was not successful.


You could then have something like this:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

double fahconv(double fah)
{
    return (fah - 32) * 5 / 9;
}

double celsconv(double cels)
{
    return (cels * 9 / 5) + 32;
}

int main()
{
    double originalTemp;
    double convertedTemp;
    char choice;

    scanf("%lf", originalTemp);

    puts("Enter (F or f) to convert from Fahrenheit to Celsius\n");
    puts("Enter (C or c) to convert from Celsius to Fahrenheit\n");
    scanf("%c", &amp;choice);

    switch (choice)
    {
        case 'c':
        case 'C':
              convertedTemp = celsconv(originalTemp);
              printf("Converted temperature from F to C: %lf", convertedTemp);
              break;
        case 'f': 
        case 'F':
              convertedTemp = fahconv(originalTemp);
              printf("Converted temperature from F to C: %lf", convertedTemp);
              break;
        default:
              printf("Invalid choice..exiting");
              return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}