The function is irrelevant here. If you turned this:
Code:
#include <stdio.h>
int degree(int m);
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main(){
int c;
c = getchar();
printf("%d", degree(c));
}
int degree( int base)
{
int p;
p = 5 * (base-32) /9;
return p;
}
into this:
Code:
#include <stdio.h>
int degree(int m);
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main(){
int c;
c = getchar();
int p;
p = 5 * (c-32) /9;
printf("%d", p);
}
that would also fail to work. The problem is getchar() -- which doesn't accept numerical input as numbers. When you type 32, getchar only gets the 3, and then converts it to its ASCII value which is 50 and passes that to the function (which correctly converts it to 10 celsius).