Hello everyone, i am new in this forum and also in C++ programming. I just started learning C++ few months ago from my university then i stuck from some assignment they give me yesterday. I need to count number's occurrences from input data. This is the assignment :

Enter 20 input numbers below :
30, 10, 20, 20, 30, 60, 90, 70, 60, 40, 30,90, 20, 30, 90, 30, 50, 60, 80, 20
a. Sum all the input number.
b. Count the occurrences of each number ! Example :
Number "10" occurrences : 1 time
Number "20" occurrences : 4 times
and so on.

I already reading some reference for counting words but somehow i can't use it to solve this problem. I need your help >.<

Recommended Answers

All 3 Replies

Try posting an attempt. You may want to store the input in an array and then sum the elements of the array with a loop. counting the numbers will be the next step. Post the sumation code first.

hmm an attempt....honestly, i really don't know how to write the code because functions that I know only conditional IF and increment and decrement for now. It really help me if you can show me some example of it.

hmm an attempt....honestly, i really don't know how to write the code because functions that I know only conditional IF and increment and decrement for now. It really help me if you can show me some example of it.

Focus on the easier part first, the summing of the numbers. Don't worry about the counting yet, which is the harder part. Whether you can do the summing part will help tell us where you are. And regarding the counting part, how familiar are you with arrays?

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.