Results 1 to 3 of 3
Thread: Boolean problems
- 09-15-2009, 11:42 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 56
- Rep Power
- 0
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 --
Java 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, 11:42 PM #2
Member
- Join Date
- Jul 2009
- Posts
- 56
- Rep Power
- 0
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, 11:57 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 56
- Rep Power
- 0
Similar Threads
-
transfer boolean to 1's and 0's
By Nikohw in forum Java AppletsReplies: 5Last Post: 09-12-2009, 10:05 PM -
1 as an integer, not boolean
By McChill in forum New To JavaReplies: 1Last Post: 05-02-2009, 10:39 PM -
Simple Boolean
By jigglywiggly in forum New To JavaReplies: 3Last Post: 01-01-2009, 06:01 AM -
boolean to string
By otoro_java in forum New To JavaReplies: 2Last Post: 01-30-2008, 06:31 AM -
boolean variables
By ravian in forum New To JavaReplies: 3Last Post: 12-31-2007, 05:58 AM
Bookmarks