### using pointers to find the mode

I have to write a program that will find the mode of a group of numbers. How should I tackle it using a pointer to find the number that appears most and producing a number of how many times the mode appears.
--------------------------------------------------------------------------------
This is what the output should look like:
Output for ex. 1 data:

The data set has 1 mode.
The value 2 appeared 3 times in the data set.

Output for ex. 2 data:

The data set has 2 modes.
The value 2 appeared 2 times in the data set.
The value 4 appeared 2 times in the data set.

Output for ex. 3 data:

The data set has no mode.

Output for ex. 4 data:

The data set has 3 modes.
The value 1.7 appeared 3 times in the data set.
The value 3.1 appeared 3 times in the data set.
The value 5 appeared 3 times in the data set.

--------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` ``````#include #include #include using namespace std; //function prototype void mode( double x[], int n); int main ( ) { const int N = 100; double x[N]; void mode (double x[],int n); int n; ifstream inFile; inFile.open("e:\\input1.txt"); n=0; inFile>>x[n]; while (x[n]!=-9999) { n++; inFile >>x[n]; } inFile.close( ); mode(x,n); inFile.open("e:\\input2.txt"); n=0; inFile >>x[n]; while (x[n]!=-9999) { n++; inFile >>x[n]; } inFile.close( ); mode(x,n); inFile.open("e:\\input3.txt"); n=0; inFile >>x[n]; while (x[n]!=-9999) { n++; inFile >>x[n]; } inFile.close( ); mode(x,n); system ("PAUSE"); return 0; } /*----------------------------------------------------*/ void mode(double x[], int n) { //locally stored variables int number_of_modes=0; int k; double *ptr;``````

--------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is what I have thus far
Last edited on
Please could you enclose your code in code tags, to make it easier for us to read? You can get the code tags by clicking the "<>" button to the right of the edit window.
Does that help? This is what I have so far
Yes, that looks much better! Thanks :)
Topic archived. No new replies allowed.