I keep getting errors talking about double pointers and i keep changing between dereferences and pointer but just keep getting errors. i don't need the address i just need to pass the address to the functions.
#include <iostream>
#include <stdlib.h> //need for rand()
using namespace std;
//GLOBAL CONSTANTS
#define ARRAYSIZE 100
#define RANDOMNUMBERS 6
//Function Declarations
void fillUpArray(int *[]);
void freqOfData(int *[], int *[]);
void outPutFreq(int *[]);
//Main function
int main()
{
//Build arrays and make them so they are the right size
int dataArray[ARRAYSIZE] = {};
int freqArray[RANDOMNUMBERS] = {}; //frequencies need to be 0 to start
int* dataPointer = &dataArray;
int* freqPointer = &freqArray;
//fill up the big data array
fillUpArray(dataPointer);
//find the frequencies and put them in the frequency array
freqOfData(dataPointer, freqPointer);
//send the frequencies to be outputted
outPutFreq(freqPointer);
//end the program
return 0;
}
//User Defined Functions
void fillUpArray(int *array[])
{
for(int i = 0; i < ARRAYSIZE; i++)
{
*array[i] = rand() % 6 + 1;
}
}
void freqOfData(int *data[], int *frequency[])
{
//walk through the entire array
for(int i = 0; i < ARRAYSIZE; i++)
{
//find out what value is in this spot and add one to that frequency
//a switch(case) is better than if statements but if you don't know it don't worry about it
if(*data[i] == 1)
{
*frequency[0] = *frequency[0] + 1;
}
else if(*data[i] == 2)
{
*frequency[1] = *frequency[1] + 1;
}
else if(*data[i] == 3)
{
*frequency[2] = *frequency[2] + 1;
}
else if(*data[i] == 4)
{
*frequency[3] = *frequency[3] + 1;
}
else if(*data[i] == 5)
{
*frequency[4] = *frequency[4] + 1;
}
else if(*data[i] == 6)
{
*frequency[5] = *frequency[5] + 1;
}
else
{
//never should go here <-- means there is mistake in our code
}
}
}
void outPutFreq(int *output)
{
cout << "The Frequency of 1 in the Array is " << output[0] << endl;
cout << "The Frequency of 2 in the Array is " << output[1] << endl;
cout << "The Frequency of 3 in the Array is " << output[2] << endl;
cout << "The Frequency of 4 in the Array is " << output[3] << endl;
cout << "The Frequency of 5 in the Array is " << output[4] << endl;
cout << "The Frequency of 6 in the Array is " << output[5] << endl;
}
Edit: I apologize for being "off-topic". This function is suppose to have a main() with two arrays that calls 3 methods. These method populate one of these arrays with random data (1 to 6). The second method calculates the frequency of the occurrences of the numbers 1 - 6. The last method will take this array of the frequencies and output it in the format "The Frequency of # in the Array is ##".