Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Exercise 5.7: diceSum problem???

+3 votes

How is my random program failing when it randomly chooses dice until it hits the desired sum (which is 7 in the example below), which is exactly what this is doing? Anyone else have this problem? I've provided a link to the picture if the copy/paste is too hard to read. ------>    https://ibb.co/iTpEgG

test #2:test2

expected output:Desired dice sum: 7

3 and 1 = 4

4 and 4 = 8

4 and 3 = 7

your output:Desired dice sum: 7

2 and 6 = 8

1 and 3 = 4

2 and 0 = 2

5 and 5 = 10

0 and 3 = 3

5 and 5 = 10

4 and 5 = 9

1 and 3 = 4

3 and 3 = 6

5 and 1 = 6

6 and 2 = 8

5 and 0 = 5

5 and 6 = 11

3 and 1 = 4

5 and 2 = 7

asked Oct 12 in CSC 211 (F17) by Caleb Westerman (1,448 points)

2 Answers

+2 votes
 
Best answer
I had this same problem. You need to recheck the range in which you are choosing your random numbers. (What numbers can you roll on a die?)
answered Oct 12 by Matthew Kuechenberg (1,041 points)
selected Oct 12 by Caleb Westerman
It is quite true that you can not roll a 0 on a die. Thanks!!
+1 vote
Is it just failing for the 7 condition, or does it work for other suns such as 9, 11?  If it doesn't work for the others, you may have been too specific in saying what condition you want it to meet.  Ie. you only checked the 7 condition and not the others.  If the other cases work and the 7 is the only one that doesn't, then there may have a bug.  But I did not have that problem.

 

If you post your code that may be able to help others
answered Oct 12 by Nicholas Garling (2,304 points)
...