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
  • 207,510
  • 22
  • 296
  • 340
laundmo
  • 290
  • 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
Kevin Wallis
  • 3,765
  • 3
  • 26
  • 42