Hi there,
Here is the problem:
I have to create a craps game:
Roll two dice. each dice has six faces representing values 1, 2, … and 6, respectively. check the sum of the two dice. if the sum is 2, 3, or 12(Called craps), you loose; if the sum is 7 or 11 (called natural) you win; if the sum is another value (i.e. 4, 5, 6, 8, 9, or 10) a point is established. continue until you roll either a 7(you lose) or the same point value(you win).
I am stuck finishing off this program.. i know i am close but i just can't seem to get to the end.. any ideas?
Once I took the line numbers out that you had included (you don't need them - the code tags will show them automatically) it seemed to compile and run OK.
Line 36 isn't quite what you said in the description, although it might have been what you intended.
Could you give us a series of dice rolls that you believe is wrong? When I try it, it seems to work as intended.
Minor points (none of which are strictly errors):
- You have put line numbers in yourself in the posted code. This is unnecessary and doesn't help because (a) we have to take them out in order to compile; (b) they don't tie up with the ones put to the side by the code tags;
- Your line (37 from the code tags, OR 36 from your code) if(sum == point && sum != 7 )
is slightly redundant, because point can't equal 7 (or the game would have already ended) so if sum == point then certainly sum != 7; just if(sum == point)
would work here.
- Your indentation for the else block is inconsistent with the rest of the if ..else .. groups (which threw me when I first looked at your code)
- It would be easier to see what was going on if you output the results of the second roll, even if they don't end the game.