I'm currently working on a basic craps simulator that needs to ouput the total wins and losses based on x number of interations, as well as output a win percentage. I haven't added the percentage part yet.
I'm running it in eclipse and sometimes I'll get the output I want and other times I'll get no output at all.
This is the code I've written so far:
public class craps { public static void main(String[] args) { int dieOne = (int)(Math.random()* 6) + 1; int dieTwo = (int)(Math.random()* 6) + 1; int roll = dieOne + dieTwo; int winCount = 0; int lossCount = 0; while (winCount + lossCount < 100) if (roll == 2 || roll == 3 || roll == 12){ lossCount++; } else if (roll == 7 || roll == 11){ winCount++; } else { dieOne = (int)(Math.random()* 6) + 1; dieTwo = (int)(Math.random()* 6) + 1; int roll2 = dieOne + dieTwo; while (roll2 != 7){ if(roll == roll2){ winCount++; break; } else { dieOne = (int)(Math.random()* 6) + 1; dieTwo = (int)(Math.random()* 6) + 1; roll2 = dieOne + dieTwo; } if (roll2 == 7){ lossCount++; } if (winCount + lossCount == 100){ System.out.println("Wins: " + winCount); System.out.println("Losses: " + lossCount); } } } }}
I'm not seeing what part of the code might return zero ouput, unless eclipse is to blame. The second while loop is supposed to be if you roll a point and are rolling until you make the point or crap out.
I'd appreciate any advice. Thanks.