Celsius to Fahrenheit program wont work right.. (ANSI C)

Im writing a program in C that will convert Celsius to Fahrenheit. When I use int to declare my fahrenheit and celsius numbers, my program runs fine.. but when I use floating-point to do it, it gives me some really WEIRD numbers.. heres my program and the log results.. someone help me.. I want to start writing programs in Cocoa and I cant until I master C and OBJ C..

#include <stdio.h>

int main (int argc, const char * argv[]) {

float fahr, celsius;
int lower, upper, step;

lower = -18;
upper = 149;
step = 18;

celsius = lower;
while (celsius <= upper) {
fahr = (9.0/5.0) * (celsius+32.0);
printf ("%d\t%d\n", celsius, fahr);
celsius = celsius + step;
}
return 0;
}

Log:
0 -1070465024
0 0
0 1077018624
0 1078067200
0 1078657024
0 1079115776
0 1079410688
0 1079705600
0 1080000512
0 1080164352

Message was edited by: Fios89

MacBook, Mac OS X (10.4.10)

Posted on Oct 31, 2007 8:20 PM

Reply
16 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Celsius to Fahrenheit program wont work right.. (ANSI C)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.