"Magic Matrix" Calculations issue

I am attempting to create a program which calculates the product of 4 vertical values in the matrix. The numbers are supposed to be randomly generated and the size of the matrix is given through the command window.

However I seem to have either not pointed my matrix through all of my functions correctly, or my logic is off somewhere as I keep getting this output regardless of the size of matrix I put in:

"the location of the highest horizontal line product is: 5 0 and is the number: 0

The overall max value is 4196352 at the above coordinates."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using namespace::std;
//srand(time(0));

int h_line(int**, int, int);
int v_line(int, int,int);
int diagnol_left(int,int,int);
int diagnol_right(int,int,int);
int zigzag(int,int,int);
int get_random_number();

//compares the value of the privious call to a function value (h_line and v_line ect...)
int comparer(int max,int checker){
  if(checker>=max){
   max=checker;}
  else{
  max=max;}
return (max);}

//Will eventually compare all of the different shape products of their respective functions
int comparer_function(int **argv, int max ,int checker, int rows, int cols){
   max=comparer(max, checker);
   checker=h_line(argv, rows, cols);
   max=comparer(max, checker);
   /*checker=v_line(**argv, rows, cols);
   max=comparer(max, checker);
   checker=diagnol_left(**argv,rows,cols);
   max=comparer(max, checker);
   checker=diagnol_right(**argv,rows, cols);
   max=comparer(max, checker);
   checker=zigzag(**argv,rows, cols);
   max=comparer(max, checker);*/
   cout<<endl;
   return (max);}

//Fills the array of the given size with random numbers
void random_array_fill(int **array_fill, int size)
{
   for (int i = 0;i < size ; i++)
   {
   for (int j = 0;j < size ; j++)
     {
   array_fill[i][j]=get_random_number();
            }}
}
//srand(time(0));
//Helper function to generate random numbers
   int get_random_number()
{
   //srand(time(0));
   int random_number = 0;
   random_number = rand() % 10; //keeps random numbers under 1500
  return (random_number);
}
//Creates the array of the command line input size to be used by the random =_array_fill function
void create_size_of_array(int **array_create, int rows, int cols){
   int *a;
   /*a=new int **[rows];*/
     for(int i=0;i<rows;i++){
      for(int j=0;j<cols;j++){
       array_create[i][j]=get_random_number();
}}}

//Takes the (vertical) product of 4 neighboring matrix values and returns the max of all of the possible products
int h_line(int *argv[], int rows, int cols){
   int max, checker, ihelp, jhelp;
   max=0;
   for (int i=0; i<rows;i++) {
     for (int j=0; j<(cols-3);j++) {
     // if (argv.length-i<4)
     int val1, val2, val3, val4;
     val1=argv[i][j];
     val2=argv[i][j+1];
     val3=argv[i][j+2];
     val4=argv[i][j+3];
       checker=val1*val2*val3*val4;
      // checker=argv[i][j]+argv[i][j+1]+argv[i][j+2]+argv[i][j+3];
        if (checker>=max){
         max=checker;
         ihelp=i;
         jhelp=j;}
       else {
       checker=checker;}}}
       cout<<"The location of the highest horizontal line product is: "<<ihelp<<" "<<jhelp<<" and is the number: "<<max;
       return (max);}

//Takes in the command line values and sends them to the correct function to calculate the product, also does some error handing
    int main(int argc, char *argv[]){
    if (*argv[0] < 1 || *argv[0] > 100 || *argv[1] < 1 || *argv[1] > 100) {
    cout<<"Please give a value between 1 and 100 that is not a decimal value for the rows and columns of the array, restart the program with the correct inputs from the command line, and remember even if you do it wrong your mother still loves you."<<endl;
return 0;
  /*cin<<&argv[0];
    cout<<endl;
    cout<<"And the width of the array please: ";
    cin<<&argv[1];*/
      }
   int rows, cols, **matrix;
   rows=atoi(argv[0]);
   cols=atoi(argv[1]);
   create_size_of_array(*(&matrix), rows, cols);
//rand function to generate the values in the array
  //random_array_fill(*(&matrix));

  int checker, max;
  //checker=box(argv);
  max=comparer_function(matrix, max, checker, rows, cols);
  //checker=h_line(argv);
  //max=comparer(max, checker);
  /*checker=v_line(argv);
  max=comparer(max, checker);
  checker=diagnol_left(argv);
  max=comparer(max, checker);
  checker=diagnol_right(argv);
  max=comparer(max, checker);
  checker=zigzag(argv);
  max=comparer(max, checker);*/
  cout<<endl;
  cout<<"The overall max value is "<<max<<" at the above coordinates."<<endl;
  }


I am going to assume I have done something absolutely idiotic, but I can't seem to find the mistake.
The matrix is never allocated.

Please beautify your code. Looking at it is like stabbing my eyes with needles.
Last edited on
Ahh brilliant of me that was.

Yes I will make it pretty once I get it done, my ideas had gone everywhere and it took over the code.

Thanks.
Topic archived. No new replies allowed.