Hi, can someone please take a look at my program and help me figure out where my logical error is. I'm pretty sure the problem is in my if..else construction.
This is a link to a blog post describing the program:
http://www.meanpc.com/2012/01/arduino-simulation-of-blind-draw.htmlThe total number of 'wins' for players 1-6 should be 32000, but I'm getting totals of over 45,000 on test runs.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
randomSeed(analogRead(0));
int player1,player2,player3,player4,player5,player6,iterations,i;
iterations = 32000;
// Pick a random number for the current player. If the current
// player picks '1', add 1 to their total. Otherwise draw again
// for the next player, subtracting 1 from the number of picks to
// draw from.
for (i = 0;i<iterations;i++){
if (random(1,7)==1) {player1++;}
else if (random(1,6)==1) {player2++;}
else if (random(1,5)==1) {player3++;}
else if (random(1,4)==1) {player4++;}
else if (random(1,3)==1) {player5++;}
else player6++;
}
// If the draw is a multiple of 1,000 - print the current results to the Serial monitor.
//if ((i%1000)==0) {
Serial.print("# ");
Serial.print(i);
Serial.print(" Plr 1: ");
Serial.print(player1);
Serial.print(" Plr 2: ");
Serial.print(player2);
Serial.print(" Plr 3: ");
Serial.print(player3);
Serial.print(" Plr 4: ");
Serial.print(player4);
Serial.print(" Plr 5: ");
Serial.print(player5);
Serial.print(" Plr 6: ");
Serial.print(player6);
Serial.println("");
//}
}