Friday, 15 January 2010

c - Printf produces wrong integers -


I'm learning something for a few days and when I use Printf to change the temperature, it displays incorrect output Does.

  int main () {char sys; Int temporary; Printf ("Enter a Tempature System [C or F]:"); Scanf ("% c", & sys); Printf ("Enter a Tempature:"); Scanf ("% s", and temp); If (sys == 'f') {int output = (temp - 32) * 5/9; Printf ("% d Fahrenheit% d Celsius \ n", Temp, Output); Return 0; } And if (sys == 'c') {int output = temp * 9/5 + 32; Printf ("% d celsius% d fahrenheit \ n", temp, output); Return 0; }}  

  scanf ("% s", and temporary);  

% s is for the format specifier wire. You are reading in an integer, so you want % d .


No comments:

Post a Comment