more advanced version euler 11

i am trying to do a more advanced version of euler problem 11 where user tells me the number of numbers to search for the greatest product. can someone tell me if my code so far for four numbers is good so far, because i am not sure if i am getting the write answer.

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
 #include <iostream>
#include <vector>
#include <string>
#include <fstream>


using namespace std;

class square{
private:
      int gridS[20][20];  
      int product;
	  int max;
	  int i;
	  int j;
public:
		square(); 
       void horizantal ();
       void vertical();
       void diagonal_R();
       void diagonal_L();
       void setMax();
       void output();
       void file();
};
int main(){
  square test;
  test.file();
    
    system("Pause");    
    return 0;
}
square::square(){
	product=1;
}

void square::setMax(){
     max=product;
}
void square:: horizantal (){
     
     for ( i=0; i<20; ++i){
         for ( j=0;j<17; ++j){
             product = gridS [i][j]*gridS[i][j+1]*gridS [i][j+2]*gridS[i][j+3];
             if(product>max){
               max=product;
             }
         } 
     }   
}
void square:: vertical(){
	
	for ( i=0; i<20; ++i){
         for ( j=0;j<17; ++j){
             product = gridS [i][j]*gridS[i][j+1]*gridS [i][j+2]*gridS[i][j+3];
             if(product>max){
               max=product;
             }
         } 
     }
}    

void square::diagonal_R(){
	
	for ( i=0; i<17; ++i){
        for ( j=0;j<17; ++j){
             product = gridS [i][j]*gridS[i+1][j+1]*gridS [i+2][j+2]*gridS[i+3][j+3];
             if(product>max){
               max=product;
             }
         } 
     }


}
void square::diagonal_L(){
	for (i=3; i<20; ++i){
        for ( j=0;j<17; ++j){
             product = gridS [i][j]*gridS[i-1][j+1]*gridS [i-2][j+2]*gridS[i-3][j+3];
             if(product>max){
               max=product;
               
             }   
         }     
     }



}  
     
void square::output(){
     cout<<max;    
     
}
void square:: file(){
       square a;
    
    
    ifstream infile;
    infile.open("grid.txt");
    if (infile.good()){
       for (i=0;i<20;i++){
           infile >> gridS[i/20][i%20];
       infile.close();
           
    } 
        } 
    a.setMax();
    a.horizantal();
    a.vertical();
    a.diagonal_L();
    a.diagonal_R();
    a.output();
}
can someone tell me if my code so far for four numbers is good so far, because i am not sure if i am getting the write answer.


Use input for which you know the correct answer. Then you will know if it generates the correct answer. (But for the record, you're definitely not getting the correct answer, since you're not operating on the data read in from the file and you only read in 20 values out of the 400 the problem requires.)

Work on and test specific areas of the program before trying to put it all together.
Topic archived. No new replies allowed.