C++: Mean Median and Mode

♀尐吖头ヾ 提交于 2019-12-01 10:34:19

Don't forget to initialise your variables:

float total = 0.0f;

In C++, a variable with automatic storage duration can be left uninitialized. Using such a variable will give you undefined behaviour.

For one thing, you haven't initialized some of your variables. In mean(), for instance, you should have this:

float total = 0;

Variables are not initialized to any defined value by default.

I recommend you increase the warning level on your compiler. If you're using g++, use -Wall. That would detect problems such as using uninitialized variables and unused variables (which you have in main()).

Mode is one of the basic statistical operators; it represent the element with the highest frequency in an array.

Your function mode is a implementation of this operator: it creates a new array in which it stores the frequency of each element in the array(i.e. how many times each element appears). The function returns the element with the highest frequency or, in case there are more with the same highest frequency, it returns the larges one.

Hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!