# Boolean problems

• 09-15-2009, 10:42 PM
Chasingxsuns
Boolean problems
Hi my program is supposed to play the game Craps 100,000 times. Basically, I have two dice and if the total of them (after being rolled) is 7, the game is one. If it's a 2 or 3, the game is lost. If it's something else I keep rolling until I get the same number or a 7. My program keeps ending after one roll, no matter what the number is. If it is a 2 or 3, it gets counted as a loss. But everything else is counted as a win so I am only getting one roll. Here is the code for the first roll --

Code:

```public class Craps {         //Plays the craps game     public static void main(String[] args) {                Random random = new Random();         int round = 1;         int dieOne;         int dieTwo;         int total = 0;         int point = 0;         int numberWon = 0;         int numberLost = 0;         int rollNumber = 1;         boolean roundWin = false;         boolean roundOver = false;                 while (round <= 100000) {             roundWin = false;             roundOver = false;             rollNumber = 1;             dieOne = random.nextInt(6) + 1;             dieTwo = random.nextInt(6) + 1;             total = dieOne + dieTwo;                             switch(total) {               case 2:               case 3:                   roundOver = true;                   break;               case 7:                   roundWin = true;                   roundOver = true;                   break;               default:                   point = total;                   break;               }                          if(round <= 10) {                         System.out.print("Round " + round + ", Roll " + rollNumber);                         System.out.print(", " + "Die1: " + dieOne );                         System.out.println(", Die2: " + dieTwo + "-- Total: " + total);                                              if(roundOver == true) {                             if(roundWin == true) {                                                                System.out.println("WIN!");                              }                             else if(roundWin == false) {                                 System.out.println("LOSE!");                             }                         }                 }```

The only way I can have a win and print "WIN!" after the first roll is if roundOver and roundWin are both true. I set them as false after every round and the only time they can be changed to true is when total == 7 on the switch statement. At least that is how I want it to be. Somehow the two booleans are changing to true for every number that isn't 2 or 3. I don't see how. Can anyone offer me any help here? Thanks.
• 09-15-2009, 10:42 PM
Chasingxsuns
Oh and I have to display output for the first 10 rounds in case it isn't obvious. But the problem here is the booleans
• 09-15-2009, 10:57 PM
Chasingxsuns
Looking at the code again, the problem is later on in the program and not what I originally thought. Apologies for wasted time