From: "Damian Yerrick" Newsgroups: comp.os.msdos.djgpp References: <82cko6$sfk$1 AT imsp026 DOT netvigator DOT com> Subject: Re: Why "c" is always zero?? Lines: 81 Organization: Pin Eight Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: <8bn24.1599$323.42573@dfiatx1-snr1.gtei.net> X-Trace: 9mmuQ65y+iFTKW7AHJ42AZwQJMsxyhdUN0GfkRa2h1TOQ4Q1vOMwYfIysYzhyIgL4XPjTnvgxZTm!HfkkfgSEeSmgYT9Z6aI5jiH+QEAykEBIxFwqYFHvGEx0eFrYlQGaOCZYl/iG8TYjR0UVYbrcgQ== X-Complaints-To: abuse AT gte DOT net X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly NNTP-Posting-Date: Sun, 05 Dec 1999 05:59:32 GMT Distribution: world Date: Sun, 05 Dec 1999 05:59:32 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Jason Yip" wrote in message news:82cko6$sfk$1 AT imsp026 DOT netvigator DOT com... >Can anyone tells me why the value of "c" is always equal to zero?? >How can I correct this? >Thanks a lot!! >#include >float ftc(n) >int n; For one thing you're using old-style K&R function defs. float ftc(int n) >{ >float c, f; int i; Where do you assign the local variable 'f' a value? > for (i=0;i<=n;i++){ > c=5/9*(f-32); > } >return c; >} >main () int main() >{ >float c, f=0; int i=0; >do >{ >c=ftc(i); >printf("\t\t F=%.2f \t\t C=%.2f\n",f,c); >f++; >i++; >} while (i<=100); >} try this #include float fahren2celsius(float fahren) { return 5/9 * (fahren - 32.); } int main() { int i; float fahren, celsius; for(i = 0; i < 212; i++) { fahren = i; celsius = fahren2celsius(fahren); printf("%f deg F = %f deg C\n", fahren, celsius); } return 0; } -- Damian Yerrick http://yerricde.tripod.com/ My .sig is too long to include in an e-mail or NG message. Go to http://www.rose-hulman.edu/~yerricde/sig.html to see it. qwtcc ehyrf