title: Using a 2d array to calculate total, high, and low
body: <p>I'm trying to find the total of books sold from each month and subject. This is what I have so far. I'm not sure how I should change the function parameters or in calling the function. I know in the main, the parameters for calling the functions are incorrect. The results should also be displayed at the bottom and right side of the table.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  #include&lt;iomanip&gt;
  
  using namespace std;
  
  typedef int Sales[108];
  
  int sales[6][12];
  static const int rows = 12;
  static const int cols = 6;
  int findhighestmath(int[][6], int);
  int findhighestcs(int[][6], int);
  int findhighestphy(int[][6], int);
  int findlowestmath(int[][6], int);
  int total(int[][6], int);
  void descendmonth(int[][6], int);
  void descendsubject(int[][6], int);
  int searching(int[][6], int, int);
  int totalmath(int[][6], int);
  
  
  int main()
  {   
  ifstream inFile;
  int sales[12][6];
  int numberofbooks = 0, sum = 0, highestmath = 0, math = 0, highestcs= 0,cs = 0;
  int totalbooks = 0, found, TotalMath = 0, TotalCS = 0, highestphy;
  int overalltotal = 0, highest = 0, lowest = 0;
  string months;
  string subject;
  string Month[12] = { "January", "February", "March", "April", "May", "June", "July",
      "August", "September", "October", "November", "December" };
  string category[6] = { "Math", "CS", "Phy", "Chem", "Bio", "Geo" };
  
  
  //Used for finding total books sold
  inFile.open("sale.dat");
  while (!inFile.eof())
  {
      for (int i = 0; i &lt; 12; i++)
      {
          for (int j = 0; j &lt; 6; j++)
          {
              sales[i][j] = 0;
              inFile &gt;&gt; sales[i][j];
          }
          cout &lt;&lt; endl;
      }
  }
  
  inFile.close();
  //Totals up all books
  for (int k = 0; k &lt; 12; k++)
  {
      for (int l = 0; l &lt; 6; l++)
      {
          sum = sum + sales[k][l];
      }
  }
  
  numberofbooks = sum;
  
  
  cout &lt;&lt; setw(40) &lt;&lt; "Book Sale Analysis" &lt;&lt; endl;
  cout &lt;&lt; setw(40) &lt;&lt; "The book store sold a total of " &lt;&lt; numberofbooks &lt;&lt; " books."
      &lt;&lt; endl;
  cout &lt;&lt; endl;
  
  cout &lt;&lt; setw(7) &lt;&lt; "Month" &lt;&lt; setw(7) &lt;&lt; "Math" &lt;&lt; setw(7) &lt;&lt; "CS" &lt;&lt; setw(7) &lt;&lt; "Phy" &lt;&lt; setw(7) &lt;&lt; "Chem"
      &lt;&lt; setw(7) &lt;&lt; "Bio" &lt;&lt; setw(7) &lt;&lt; "Geo" &lt;&lt; setw(9) &lt;&lt; "Total" &lt;&lt; setw(7)
      &lt;&lt; "High" &lt;&lt; setw(7) &lt;&lt; "Low" &lt;&lt; endl;
  
  
  //Used for displaying a table of books sold
  inFile.open("sale.dat");
  while (!inFile.eof())
  {
      for (int i = 0; i &lt; 12; i++)
      {
          for (int j = 0; j &lt; 6; j++)
          {
              sales[i][j] = 0;
              inFile &gt;&gt; sales[i][j];
              cout &lt;&lt; setw(7) &lt;&lt; sales[i][j] &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
  }
  
  inFile.close();
  
  
  
  for (int i = 0; i &lt; 12; i++)
  {
      for (int j = 0; j &lt; 6; j++)
      {
          math = math + sales[i][j];
      }
  }
  
  //Total, high, and low outputs for subjects
  cout &lt;&lt; endl;
  TotalMath = totalmath(sales, math);
  cout &lt;&lt; "Total" &lt;&lt; setw(5) &lt;&lt; TotalMath &lt;&lt;endl;
  
  highestmath = findhighestmath(sales, math);
  cout &lt;&lt; "High" &lt;&lt; setw(5) &lt;&lt; highestmath;
  highestcs = findhighestcs(sales, cs);
  cout &lt;&lt; setw(5) &lt;&lt; highestcs &lt;&lt; endl;
  highestphy = findhighestphy(sales, numberofbooks);
  cout &lt;&lt; setw(5) &lt;&lt; highestphy;
  
  lowest = findlowestmath(sales, math);
  cout &lt;&lt; "Low" &lt;&lt; setw(5) &lt;&lt; lowest &lt;&lt; endl;
  
  //Sorted analysis
  cout &lt;&lt; endl;
  cout &lt;&lt; "Sorting month in ascending order of total sale" &lt;&lt; endl;
  
  cout &lt;&lt; endl;
  cout &lt;&lt; "Sorting book category in ascending order of total sale" &lt;&lt; endl;
  
  //Search month and book sales using binary search
  found = searching(sales, numberofbooks, totalbooks);
  cout &lt;&lt; months &lt;&lt; endl;
  cout &lt;&lt; subject &lt;&lt; endl;
  cout &lt;&lt; "The total sale is " &lt;&lt; found &lt;&lt; endl;
  
  return 0;
  
  }
  
  
  //Function finds highest sale value for math
  int findhighestmath(int arr[][6], int b)
  {
  int highestsale = arr[0][0];
  for (int i = 0; i &lt; b; i++)
  {
      for (int j = 0; j&lt;b; j++)
      {
          if (arr[i][j]&gt;highestsale)
          {
              arr[i][j];
              highestsale = arr[i][j];
          }
      }
  }
  return highestsale;
  }
  
  
  int findhighestcs(int arr[][6], int b)
  {
  int highestsale = 0;
  for (int i = 0; i &lt; b; i++)
  {
      for (int j = 0; j &lt; b; j++)
      {
          if (arr[i][j]&gt;highestsale)
          {
              arr[i][j];
              highestsale = arr[i][j];
          }
      }
  }
      return highestsale;
  }
  
  
  int findhighestphy(int arr[][6], int b)
  {
  int highestsale = 0;
  for (int i = 0; i &lt; b; i++)
  {
      for (int j = 0; j &lt; b; j++)
      {
          if (arr[i][j]&gt;highestsale)
          {
              arr[i][j];
              highestsale = arr[i][j];
          }
      }
  }
  return highestsale;
  }
  
  //Function finds lowest sale value
  int findlowestmath(int arr[][6], int b)
  {
  int lowestsale = 0;
  for (int i = 0; i &lt; b; i++)
  {
      for (int j = 0; j &lt; b; j++)
      {
          if (arr[i][j] &lt; lowestsale)
          {
              arr[i][j];
              lowestsale = arr[i][j];
          }
      }
  }
  return lowestsale;
  }
  
  
  int totalmath(int arr[][6], int total)
  {
  for (int row = 0; row &lt; 12; row++)
  {
      for (int col = 0; col &lt; 1; col++)
      {
          arr[row][col];
          total = arr[row][col];
      }
  }
  return total;
  }
  </code></pre>