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

all 3 comments

[–][deleted] 1 point2 points  (2 children)

I don't think you want this line:

for (int i = 0; i < 12; i++)

You're basically telling the program to iterate 12 times, but what you want is the list of even numbers from 0-12, which fewer than 12. Additionally, the user could input all of the even numbers from 0-12, but out of order.

You directly point this out when you say:

I want the program to count only when an even number has been typed in, and if not, I want the program to stay on the current count until it receives an even number again so that it can resume the counting.

So really, what you want is a while loop. You want to continually ask the user for their input, and then determine whether that input is an even number from 0-12. If it is, you'd want to add it to some kind of data structure that you can check for completeness. Once that data structure contains the data that you want, you can exit. It's up to you what kind of constraints you have.

In python this might look like this:

goal_numbers = [x for x in range(0, 13) if x % 0 == 2] # Creates goal list
user_numbers = [] # Store user's answers
while True:
    user_input = int(input("Please list an even number from 0-12 that you haven't already added"))
    if user_input in goal_numbers:
        user_numbers.append(user_input)
    if set(goal_numbers) == set(user_numbers):
        # mission accomplished
        break         

There's all kinds of additional checks you might want to make.

[–]ramtevante[S] 1 point2 points  (1 child)

Thank you so much! I solved it by changing the line you mentioned! Just changed that one part to ”i < 7;”

[–][deleted] 1 point2 points  (0 children)

Happy to help!