I am working on a project which analyzes and predict wave patterns, but the thing is that the code of nested if/else is becoming more harder to manageable, here is snippet:
for (int x = 1; x <= 24; x++)
{
if ((15 <= Angles[x]) && (Angles[x] <= 30))
{
if(x<=6)
{
counter=counter+4;
if (edges[x] < edges[x+2]) { counter = counter - 4; }
else{counter=counter+5; };
if (Angles[x] < Angles[x + 2]) { counter = counter - 6; }
else{counter=counter + 4; };
if ((edges[x+1] - edges[x]) < (edges[x + 3] - edges[x + 2])) { counter= counter - 6; }
else{counter-counter + 5; };
if (gradient[x] < gradient[x + 2]) { counter = counter - 6; }
else{counter=counter + 5; };
};
if((7<=x)&&(x<=12))
{
counter = counter - 10;
if (edges[x] < edges[x+2]) { counter = counter - 5; }
else{counter=counter + 6; };
if (Angles[x] < Angles[x + 2]) { counter = counter - 7; }
else{counter=counter + 6; };
if ((edges[x+1] - edges[x]) < (edges[x + 3] - edges[x + 2])) { counter =
counter - 6; }
else{counter-counte+7; };
if (gradient[x] < gradient[x + 2]) { counter = counter - 6; }
else{counter=counter+8; };
};
if((13<=x)&&(x<=18))
{
counter = counter - 30;
if (edges[x] < edges[x+2]) { counter = counter - 7; }
else{counter=counter + 6; };
if (Angles[x] < Angles[x + 2]) { counter = counter - 7; }
else{counter=counter + 5; };
if ((edges[x+1] - edges[x]) < (edges[x + 3] - edges[x + 2])) { counter =
counter - 7; }
else{counter-counter+5; };
if (gradient[x] < gradient[x + 2]) { counter = counter + 5; }
else{counter=counter + 5; };
};
//there are more waves classification and weightage to come//
if ((30 <= Angles[x]) && (Angles[x] <= 45)){}.....
if ((45 <= Angles[x]) && (Angles[x] <= 60)){}.....
if(60 < Angles[x]){}....
};
Angles is a container storing wave angle values. edges are peak and trough of waves. gradient contains the gradient value of wave counter is the weightage of the current pattern. values are stored in serial manner in a vector.
This is just a rough stripped down snippet (ignore syntax error if you find one). Each pattern consists of a for loop with nested if/else within it. There are 13 more patterns.
I have already crossed 5000 lines just writing those if/else for loops. Can you guys help me with making this more manageable?