### calculating frequency of the numbers entered

I have to use arrays to sort the values entered from the smallest to the largest, and calculate the frequency of those numbers typed. But I keep having an error in the function to calculate frequency, and frankly, I don't really know what I'm doing.... =( Please help me with creating frequency function and correcting other mistakes from the code!

===============================================================================

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128`` ``````// Includes #include #include #include #include using namespace std; // Function Prototypes int fillArray(double array[]); void showArray(double array[], int n); void bubbleSort(double array[], int n); void swap(double array[], int i, int j); int frequency (int array[], int n, int value[], int counts[]); // Main int main(void) { // Prompt the user cout << "This program will help the user to sort the entered values, and show their frequency." << endl; cout << "Please follow the direction correctly." << endl; cout << endl; cout << endl; cout << endl; // Create an array of doubles double dataArray[50]; int arraySize = 0; // Fill the array arraySize = fillArray(dataArray); // print the array showArray(dataArray, arraySize); // Sort the array bubbleSort(dataArray, arraySize); // print the array showArray(dataArray, arraySize); system("pause"); return 0; } // Function Definitions int fillArray(double array[]) { // Function to fill an array with doubles int n = -99; // Number of data point // Prompt for the number of data points cout << "How many values will you enter? "; cin >> n; // Loop to enter data for(int i = 0; i < n; i++) { // Enter the data point cout << "Enter data point " << (i+1) << ": "; cin >> array[i]; } return n; } void bubbleSort (double array[], int n) { // Function that sorts an array of doubles // Nested loop to compare each element with those that follow it for(int i = 0; i < n - 1; i++) { for(int j = i+1; j < n; j++) { // Comparison if(array[j] < array[i]) { swap(array, i, j); } } // End of inner loop } // End of outer loop return; } void swap (double array[], int i, int j) { // Function to swap the elements at indicese i and j // Swatching the two values by using an intermediate temporary variable // remember the Tower of Hanoi puzzle double temp; temp = array[j]; array[j] = array[i]; array[i] = temp; } int frequncy (int array[], int n, int value[], int counts[]) { // Single for loops with an if-else block for(int i = 0; i < n; i++) { int value [50]; int counts [50]; if(array[i] != value[i]) { // values are different cout.width(6); cout << right << counts << endl; } else(array[i] == value[i]) { // values are same cout.width(6); cout << right << counts++ << endl; } } // End of for loop } // End of function void showArray(double array[], int n) { // Function to print an array to the screen // print a linefeed cout << endl; // Loop through the array printing the values for(int i = 0; i < n; i++) { // Print element i cout.width(6); cout << left << array[i] << endl; } // print a linefeed cout << endl; }``````

You shouldn't need a condition with your else statement. It should just look like this.

 ``1234`` ``````else { // values are same cout.width(6); cout << right << counts++ << endl; }``````

Topic archived. No new replies allowed.