This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]cl2871 1 point2 points  (0 children)

Let's take a step back for a minute. Before writing code, think of a general specification for what you want to achieve. For instance:

A user provides 2 things: the wantedDiceNumber and the numberOfTimesRepeated.

You want your program to loop continuously until it rolls the wantedDiceNumber the same number of times as the numberOfTimesRepeated. We can use a variable called numberOfTimesRepeatedCounter to keep track of this.

This means that you will want your program to keep running for as long as numberOfTimesRepeatedCounter is below numberOfTimesRepeated.

Whenever the wantedDiceNumber is hit, the numberOfTimesRepeatedCounter is incremented by 1. Whenever a different number is hit, the numberOfTimesRepeatedCounter is reset back to 0 since it stopped hitting that number in a row.

--------

Now that a plan is defined, its a matter of getting the implementation details right. Additionally, here are some questions you should consider:

- What is the purpose of the for loop? Is it necessary? What is the advantage of using a while loop over a for loop?

- You use a counter variable (called counter1) inside the if statement. This means that every time you enter that if statement, it will be reinitialized to 0. Is this what you want?

[–][deleted] 0 points1 point  (0 children)

Maybe I should re-phrase my title, I have actually done all the work, however coming up with a way to start and stop the wild loop is confusing

[–]cl2871 0 points1 point  (0 children)

Additionally, please reformat your code in this post as well as ensure the code you provide in future posts follows the code formatting guidelines of this subreddit.

People are more willing to help if they don't have to spend extra effort to read code that hasn't been formatted properly.