Mail Archives: djgpp/1999/12/05/03:10:06
Message-ID: | <384A10E5.E5BD0A30@sgi.net>
|
From: | John & Susie <jdk AT sgi DOT net>
|
X-Mailer: | Mozilla 4.5 [en] (WinNT; I)
|
X-Accept-Language: | en
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Why "c" is always zero??
|
References: | <82cko6$sfk$1 AT imsp026 DOT netvigator DOT com>
|
Lines: | 45
|
Date: | Sun, 05 Dec 1999 02:14:45 -0500
|
NNTP-Posting-Host: | 209.166.129.179
|
X-Complaints-To: | abuse AT stargate DOT net
|
X-Trace: | news.sgi.net 944378118 209.166.129.179 (Sun, 05 Dec 1999 02:15:18 EST)
|
NNTP-Posting-Date: | Sun, 05 Dec 1999 02:15:18 EST
|
Organization: | Stargate Industries, LLC
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
> Jason Yip wrote:
>
> Can anyone tells me why the value of "c" is always equal to zero??
> How can I correct this?
> Thanks a lot!!
>
> #include <stdio.h>
<---- <float.h> is not declared.
> float ftc(n) <---- you dont use the passed value 'n' in your function -
> int n; <-----but you declare it old style here? (the address
where it would be stored happened to be
zero or
your compiler automagicly set it to 0)?
Your compiler
should warn you here - dump this.
> {
> float c, f; int i; <---- f = 0 (dont count on it, could be anything)
> for (i=0;i<=n;i++){ <---- 'f' is not modified
> c=5/9*(f-32); <---- c = 5/9*(0-32) should be about -17.7777
}
> return c; <------------ you return 'c' which should be -17.7777
but get 0 (didnt declare float.h,
possibly)?
> }
> 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);
> }
Actually, trying to compile this under NT wedged Rhide.
Make some changes, use one loop, use doubles instead of floats and do
visit...
comp.lang.c.moderated
comp.lang.c
- Raw text -