Hey, I am having a small problem with a program I am doing. What I am trying to do is multiply a series of fractions until they equal 3.1416 at least. Now I have my fractions correct, but for some reason it won't divide them into variable C, then multiply it by the place holder variable d until it reaches 3.1416. C comes up as 0 each time I try. Ive tried lots of different ways but for some reason it always returns 0 or 1. Any ideas or suggestions?
Code:
#include <stdio.h>
void main(void)
{
int i; // iteration loop
int topFrac, botFrac, d; //topFrac = top fraction, botFrac = bottom fraction,
// c = their result, d = temp var to hold c for next loop.
double pi; //value the product will be assigned
float c;
d = 1; // carry over variable
botFrac = 1;
c = 1;
topFrac = 2;
for(i=1; i<=200; i++)
{
if(i%2==0)
{
topFrac = topFrac + 2;
}
else
{
botFrac = botFrac + 2;
}
d = c;
c = topFrac / botFrac;
printf("%d / %d = %f\n", topFrac, botFrac, c);
}
}