Mail Archives: djgpp/1999/12/05/04:39:48
From: | "Shawn" <NRLax27 AT aol DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
References: | <82cko6$sfk$1 AT imsp026 DOT netvigator DOT com>
|
Subject: | Re: Why "c" is always zero??
|
Date: | Sun, 5 Dec 1999 03:45:42 -0500
|
Lines: | 53
|
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
|
NNTP-Posting-Host: | crbt-170.res.umass.edu
|
Message-ID: | <384a2667@oit.umass.edu>
|
X-Trace: | 5 Dec 1999 03:46:31 -0500, crbt-170.res.umass.edu
|
Organization: | University of Massachusetts, Amherst
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie 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 <stdio.h>
>float ftc(n)
>int n;
>{
>float c, f; int i;
> for (i=0;i<=n;i++){
> c=5/9*(f-32);
> }
>return c;
>}
>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);
>}
Jason,
Have you tried initializing the value of f in your function ftc() to
some value before you start? A solution might be:
float ftc(int n)
{
float c, f;
int i;
for(f=0, i=0; i<=n, i++)
c=5/9*(f-32);
return c;
}
However, some points:
What is the purpose of this function? This loop doesn't appear to be doing
too much. You are calculating the same value n times and then returning the
value.
Hope this helps!
-Shawn
- Raw text -