Hello everyone,
I have a problem with my latest assignment. I have been tasked with a program that uses a pointer to a pointer in a function in a multidimensional array. Below is what I have, the first scenario works 2x2 the second does not 2x6.


//Purpose: This program will display the area with the most crabs present.


 

Code:
#include <iostream>

#include "hw00.hpp"

using namespace std;


 

int main()

{

  int test_cases;    //number of test cases entered from user

  int test_case=0;      //number to keep track of test cases

  int width, height;    //dimensions for the matrix

  const int DEF_VAL=0;  //default value to initialize the matrix

  int *p, *ptr;

  int value1, value2;        //entered by user

  int count, temp;

    

  cin>>test_cases;    //user enters number of test cases

  do 

  {

    width=0;

    height=0;

    cin>>width;        //user enters dimensions

    cin>>height;

    p=getmatrix(width, height, DEF_VAL);    //matrix created

    ptr=new int [height];

    

    for(int i=0; i<width; i++)

    {  

      cin>>value1;

      p[i]=value1;

    } 

    for(int j=0; j<height; j++)  

    {

      cin>>value2;

      ptr[j]=value2;

    }    

    cout<<"#"<<test_case<<":  ";    //output formatting

     

    if(p[0]+ptr[0]>0)            //verifies input was made

    {  

      count = 0;

      temp=p[0]+ptr[0];  

      for(int i=0; i<width; i++)

      {

        for(int j=0; j<height; j++)        

        {

          if(p[i]+ptr[j]>temp )

          {

            temp=p[i]+ptr[j];        //adds the column

            count=i;            // keeps track of which column

          }

        }

      }  

    }    

    cout<<count<<endl;               //outputs column with highest numbers

    test_case++;

  }while(test_case < test_cases);    //continues through the test cases

  

  return 0;

}
Any help is greatly appreciated.

Thanks