How do I get a array to just count how many numbers there are instead of counting the value of each number?

Posted by Chad Loos on Stack Overflow See other posts from Stack Overflow or by Chad Loos
Published on 2011-11-19T00:44:54Z Indexed on 2011/11/19 1:50 UTC
Read the original article Hit count: 149

Filed under:
|

//This is the output of the program

*** start of 276 2D Arrays_03.cpp program ***

Number    Count     Total
   1        3         3
   2        6         9
   3       15        24
   4        6        30
   5        9        39

*** end of 276 2D Arrays_03.cpp program ***



#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

const int COLUMN_SIZE = 13;

int main(void)
{
    const int ROW_SIZE = 3;
    const int COUNT_SIZE = 5;

    void countValues(const int[][COLUMN_SIZE], const int, int[]);
    void display(const int [], const int);

    int numbers[ROW_SIZE][COLUMN_SIZE] = {{1, 3, 4, 5, 3, 2, 3, 5, 3, 4, 5, 3, 2},
                                    {2, 1, 3, 4, 5, 3, 2, 3, 5, 3, 4, 5, 3},
                {3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5}};

    int counts[COUNT_SIZE] = {0};
    string choice;

    cout << "*** start of 276 2D Arrays_03.cpp program ***" << endl;
    cout << endl;

    countValues(numbers, ROW_SIZE, counts);

    display(counts, COUNT_SIZE);

    cout << endl;
    cout << endl;
    cout << "*** end of 276 2D Arrays_03.cpp program ***" << endl << endl;

    cin.get();
    return 0;
}   // end main()

This is the function where I need to count each of the values. I know how to sum rows and cols, but I'm not quite sure of the code to just tally the values themselves.

void countValues(const int numbers[][COLUMN_SIZE], const int ROW_SIZE, int counts[])

This is what I have so far.

{
 for (int index = 0; index < ROW_SIZE; index++)
  counts[index];
{

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework