Member Avatar

I need to write a program where a user inputs positive integers between 0 and 20 that uses an array to count how many times each integer is input. I cannot save integers that are input, i must save the count of integers that are input. I don't know where to start. please help

Recommended Answers

A perfctly good suggestion, but it would be simpler to let the array elements default to zero, then you wouldn't need to initialise it or add 1 at the end!

Jump to Post

All 2 Replies

Make an array of 21 integers (default the values to -1).
When a number is entered, go to the offset representing that number and add 1 to it.
Of course, the final value of each will need an additional 1 added to report true hit-count.

It seems as if you would allow the user to enter a number signifying when to stop (like -1).

A perfctly good suggestion, but it would be simpler to let the array elements default to zero, then you wouldn't need to initialise it or add 1 at the end!

commented: A better option for the solution! +13
Be a part of the DaniWeb community

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