Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annoying Error

 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My game runs 1000 games of craps, displays the number of wins and losses, average chance to win and averge turns at the end and also number of time won and lost on each number of rolls.

1. It displays 0 for the first number I print, when it should be some very large number (ex 200 or 300).

2. The average chance of winning is not showing. I put in several different places but its wont show.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the average displays for me, it is the "Chance of winning" which doesn't display - you don't have a winpField.setText() anywhere.

another thing
for (int i=0; i < count.length; i++)
{
...
firstRoll = true;
}

perhaps this should be firstRoll = false;
 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, Im so stupid sometimes, thanks for pointing it out.

The problem with the 0 isnt fixed. Firstroll = true so It knows it the first roll when it goes into the loop again. Incase you didnt win or los on the first turn firstRoll gets set to false in the default case statement..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run it this is what I get
Die 1 - 3
Die 2 - 3
Sum Is - 4
Point Is - 4
Wins - 498
Loses - 502
Chance of Winning - ""
Average Turns - 3.483

Not sure where the 0 comes in, or "what should be a very large number(ex 200 or 300)"

The display would probably be much better if you changed from FlowLayout to GridLayout
 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the numbers on the command prompt in the back of the applet, thats what im talking about. New code that has chance of winning:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at the start of the for loop, turns is set to 0
on entry to the while loop, rollDice() is called;
rollDice() contains turns = turns + 1;
i.e. turns with a value of 0 can never be used

 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! So sorry having you go through my program like this. In the future I will hopefully not have a problem like this. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic