I'm writing a Lottery program where the user type sin 4 numbers between 1 and 30, the program generates 4 random numbers. In my program I have stored the random numbers and the numbers chosen by the player in 2 separate arrays. The problem I have is that I dont know how to make the program tell the user how many numbers they have matched.

Is there an easier way than writing so many if statements, is there a way of comparing the arrays? If anyone can help me I will be very grateful.

Mus.

A simple yet effective way to solve this would be to use a for loop to compare the elements of each array to the other using the for loop's variable. If they were equal, increment a counter variable (but don't forget to reset it after each use)

Thanks a lot for you help I used a for loop like you said and it works fine.

Mus

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.