Help i would like function MODE excel in c++

Ex. 3 4 5 6 6 7
run , answer is 6

Thank you very much
And your question/problem is what?
is problem
i can not do it

and i low skill english because i'm from thailand i'm sorry
Well what is the problem? We're not mind readers, you need to explain the problem fully and what it is you are trying to solve.
i understand funtion MODE in ms excel, but i can not write it off as a c++.
The "mode" is the number which appears the most times in the input data. Hence, in the OP's example, the answer is 6, because it appears more times than any other number.

My solution would be to use a std::map. For each number that you read from the list, check if it already has an entry in the map. If it doesn't (i.e. it's the first instance of this number that you've read), then create the entry and initialise it to 1. If it already has an entry, then increment it.

Once you've finished reading all the numbers, then iterate over the map to find the entry with the highest value. That entry is the mode.

e.g. with the data in the OP, you'd end up with:

map[3] = 1
map[4] = 1
map[5] = 1
map[6] = 2
map[7] = 1

Since map[6] has the highest value, 6 is the mode.
Last edited on
thank you
i not to know, because i begin learn introduction programming in university
but teacher give home work very hard
i would like
example.
enter number : x
enter number : x
enter number : x
enter number : x
enter number : x
enter number : maximum 20 number

mode is ...

Well, we're not going to write your homework for you. The whole point of the homework is for you to think about the problem, and work out some logic that would do what you want, and then write some code that would perform those logical steps. You'll learn better by doing that yourself, then by asking us to do it for you.
you can do a for loop to acquire 20 numbers like this.

int number[ 20 ];

for ( int i = 0; i < 20; i++ )
{
cout << "Enter a number: ";
cin >> number[ i ];
}
ok,
i will attempt think oneself

thank you very much
Topic archived. No new replies allowed.