# Random Number Game CSI help

• 01-09-2012, 02:14 AM
cmballer
Random Number Game CSI help
I have a program for my Computer Science I class that I need to do, and the description is:

A game between players A and B is played as followed.
A coin is tossed three times or until a head comes up, whichever occurs first.
As soon as a head comes up, player A collects \$1 from player B.
If no head comes up on any of the three tosses, player B collects \$6 from player A.
In either case, the game is over.
Your program is to simulate this game 1000 times to help decide whether A or B has the advantage, or if it's a fair game.
Assume that A and B both start with \$100 in each game.

When I run the code that I have, it doesn't print anything except for the first System.out.print before the for loop, so I was wondering if you could help me figure out if there are any errors I have in my code.

Code:

```public class BonusProgram3{     public static void main(String args[])     {             int i,zha,ZhangA=100,ZhangB=100;             System.out.println("Player A and Player B both start with \$100. \nAfter simulating the game 100 times, here are the results.");             for(i=1; i<=1000; i++){                   int coin[]=new int[3];                               for(zha=0; zha<3; i++){                 coin[zha]=(int)(Math.random()*2);                 if(coin[zha]==1){                     ZhangA=ZhangA+1;                     ZhangB=ZhangB-1;                 }         }                 if(coin[0]==2 && coin[1]==2 && coin[2]==2){             ZhangA=ZhangA-6;             ZhangB=ZhangB+6;         }     }         if(ZhangA>ZhangB)         System.out.println("Player A, with \$" +ZhangA+ " beats Player B, with \$" +ZhangB+ ".");             if(ZhangB>ZhangA)         System.out.println("Player B, with \$" +ZhangB+ " beats Player A, with \$" +ZhangA+ ".");             if(ZhangA==ZhangB)         System.out.println("Player A, with \$" +ZhangA+ " tied Player B, with \$" +ZhangB+ ".");     } }```

Thank you!
• 01-09-2012, 02:48 AM
Norm
Re: Random Number Game CSI help
Add some more printlns to show the execution flow and the values of the variables as they change.

Change the number of loops down from 1000 for testing with the printlns showing the execution.