0

I was writing a simple processing script that does an random boolean and counts how oft its 1 instead of 0.

then I added an counter of the total amount an random is done. i wanted to use that for claculating the percentage of the 1ns. anything works fine to this point. then I wanted to do the calculating. it shows 0 no matter what i do. the code goes like

bool r; //boolean for random
int t;  //t fr true or 1
int f;  //f for false or 0
int cnt; //cnt for total count
float p; //for the percentage
Void draw(){
 r = int(random(2));
 if (r==0){int(f++);}
 if (r==1){int(t++);}
 if (r<100){cnt++;}
 p = t / cnt * 100; //calculating percentage.
 text(p,10,100);   //draws text on sceen at x=10 and y=100 but it always draws 0
}

Whats is wrong with that? What did I do wrong?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
laundmo
  • 318
  • 5
  • 16

1 Answers1

0

I think it is this problem: Why dividing two integers doesn't get a float?

So you can write something like that:

(t * 100.0f)/cnt
Community
  • 1
  • 1
wake-0
  • 3,918
  • 5
  • 28
  • 45
  • Does this work for you? When not you can put a breakpoint to `text` and check `p` maybe your `text` function is wrong. – wake-0 Jun 01 '16 at 07:23
  • thanks that worked out nicely. i didnt know abot Why dividing two integers doesn't get a float? – laundmo Jun 01 '16 at 07:24
  • text worked allright as i commented earlier i use text way more than one time and it works – laundmo Jun 01 '16 at 07:25