Celsius and Fahrenheit Converter I'm very new to programming in C and I attempted to make a program that converts temperatures to and from Fahrenheit and Celsius. I have been running the program and I have realized that not all conversions are correct. For example, if I use the boiling point of water (100C or 212F), I get an incorrect answer. I thought that I used the correct formulas. I was wondering if you wouldn't mind reviewing this quick program.

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

int main(void) {

    float c;
    float f;
    int w;

    printf("Type 1 if you would like to convert to Farenheit\n");
    printf("Type 2 if you would like to convert to Celcius\n");

    scanf("%i", &amp;w);


// Loop to make sure value is 1 or 2

    while(w != 1 &amp;&amp; w !=2) {

        fprintf(stderr, "You didn't input a valid number. Please Try Again\n");
        scanf("%i", &amp;w);    
    }

// Celsius --&gt; Fahrenheit
    if(w == 1){
        printf("Input the Celcius Temperature\n");
        scanf("%f", &amp;c);
        printf("You entered %f\n", c);
        f = c * (9./5.) + 32.;
        printf("%f in Fareheit is %f\n", c, f);
     }

// Fahrenheit --&gt; Celsius
    if(w == 2){
        printf("Input the Farenheit Temperature\n");
        scanf("%f", &amp;f);
        printf("You entered %f\n",f);
        c = (f - 32.) * (5./9.);
        printf("%f in Celcius is %f\n", f, c);
    }


    return 0;
}
Spelling "Celsius" (3 places)

printf("Type 2 if you would like to convert to Celcius\n");

Better to get return value of input functions (4 places).  Even in learner code, it saves time during debug

// scanf("%i", &amp;w)
int ret = scanf("%i", &amp;w);
assert(ret == 1);

Infinite loop should user enter non-numeric input as the offending input is not consumed.

while(w != 1 &amp;&amp; w !=2) {
  fprintf(stderr, "You didn't input a valid number. Please Try Again\n");
  // scanf("%i", &amp;w);    
  ret = scanf("%i", &amp;w);    
  assert(ret == 1);
}

Style: Suggest .0.  Also since the input and output are float, code could use float constants.  In general, unless floating point math is intensive or has larges array of data, recommend using double as that is C's default FP type.

// f = c * (9./5.) + 32.;
f = c * (9.0/5.0) + 32.0;
f = c * (9.0f/5.0f) + 32.0f;

Functional simplification: Rather than enter a number to indicate the desired temperature scale, enter 'C' or 'F'.

char scale;
char scale_new;
ret = scanf("%f %c", &amp;temperature, &amp;scale);
assert(ret == 2);

switch (scale) {
  case 'C':
  case 'c': 
    temperature_new = temperature*9/5 + 32;  // math is all FP
    scale_new = 'F'; 
    break;
  case 'F':
  case 'f': 
    temperature_new = (temperature - 32)*5/9;  // math is all FP
    scale_new = 'C'; 
    break;
  default:
    // Handle bad scale
}
printf("... converts to %f %c\n", temperature_new, scale_new);