### 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115`` `````` #include #include #include #include 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<> 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.