1. ## Somewhat easy problem

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);

}

}```

2. Code:
`int topFrac, botFrac, d;`
Perhaps you should declare them as double. Its only then you can expect result as a double. If you divide int/int u will get int. If you do int/double = get double. If you fo 10 / 100.0 you will get double. Thats how it works. Either one of your operand should be double or float.

And make sure you return an int from your main. It should be int main not void main.

Code:
```int main
{
return 0;
}```
See FAQ for more details.

ssharish

3. Thanks buddy! Although it still doesn't work, I did get some results at least. I think I am just going to scrap it, I think I went the wrong way with it. I hate PI lol. Thanks again and good advice. Ill remember that!

4. I think in this case, since topFrac and botFrac are always whole numbers,it would probably be better to make them ints (or unsigned ints, since they're also nonnegative) and use a cast when necessary to force floating-point division - for example,
Code:
`c = (float)topFrac / botFrac;`
Standard 32-bit IEEE-754 floats only have 23 binary bits of precision == 6 or 7 decimal digits. If you make the variables floats, they will start to be imprecise when their values get about that big, which is much smaller than the maximum value of a 32-bit signed or unsigned int (about 2 billion and 4 billion, resp.). On the other hand, if you make them 64-bit IEEE-754 doubles, they have 52 binary bits of precision == about 15 or 16 decimal digits, so they can get bigger than if they were 32-bit ints, but doing simple integer increments such as adding 2 are more expensive than the same operation on ints.

5. Code:
`Standard 32-bit IEEE-754 floats only have 23 binary bits of precision..`
24 bits if you count the hidden bit

You'll begin to have some problems representing integer with IEEE32 format once you reach 2^24 which is 16 777 216...

For the IEEE64 format, you'll have the same problems when you'll reach 2^54 which is 18 014 398 509 481 984...