Need some assistance with mean, mean, and mode
Apr 1, 2011 at 2:49am UTC
So...basically I have an application that collects numbers and when the user presses enter the application stops collecting numbers and shows the mean, median, and mode of the numbers entered.
Here is my code thus far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void GetNums(vector<int >&values)
{
int i= -1;
string temp;
do
{
i++;
values.resize(i+1);
cout << "Please enter a number <ENTER to quit>: " ;
getline(cin, temp);
values[i] = atoi (temp.c_str());
} while (temp != "" );
}
void ShowNums(vector <int > values)
{
//Need to add a mean, median, & mode
}
void Swap (int & first, int & second)
{
int temp = first;
first = second;
second = temp;
}
void SortNums (vector<int >values)
{
for (int i=0; i<values.size(); i++)
for (int j=0; j<values.size(); j++)
if (values[j] < values[j+1])
Swap(values[j], values[j+1]);
}
void main()
{
vector <int > values;
GetNums(values);
cout << endl;
SortNums(values);
cout << endl;
ShowNums(values);
cout << endl;
}
I'm not that familiar with vectors so my question is, what is the best way to go about making the mean, median, and mode? Thanks for those that help!
Apr 1, 2011 at 2:54am UTC
Topic archived. No new replies allowed.