# Simple Code error

• 08-10-2007
JJFMJR
Simple Code error
Hey all, I've been programming for a while, and I can't seem to figure out this little error.

Code:

```#include <iostream> int main() {     int Players = 12;  //12 Players         float PChances[Players]; //Each Player has his/her own chance to draw shooter         float PreviousChances = 0;         int y = 12;         for(int x = 0; x < 12; ++x)         PChances[x] = 0;         for(int x = 0; x < 12; ++x)     {         if(y > 0)             PChances[x] = ( 1/y );  //Keeps returning as 0         std::cout << 1/y;                     --y;     }         if(PChances[3] > 0)         std::cout << "TRUE";             std::cin.get(); }```
The output is:
000000000001

Anything below 12 is resulting in 0
If you can tell me why 1/y is always equaling 0 i would appreciate it greatly.
• 08-10-2007
laserlight
Integer division: 1/12 = 0
• 08-10-2007
JJFMJR
I thought that might be the problem, however I've been absent for so long i guess i forgot regular division. How can i not get 0?
• 08-10-2007
laserlight
Quote:

How can i not get 0?
Do a 1.0/y.

Also, I note that you are using a variable length array extension by accident. You probably want to write:
Code:

```const int Players = 12;  //12 Players float PChances[Players] = {0}; //Each Player has his/her own chance to draw shooter```
With the above code, you no longer need a loop to initialise all the elements to 0. I think that you might as well use double instead of float. Floating point literals are of double type unless otherwise specified.