Given the following code which outputs the second biggest integer in an array of 4 integers why do you need the secondMax if statement before firstMax if statement?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int firstMax = array[0];
int secondMax = array[1];
for (int i = 0; i < 4; i++)
{
if(array[i]>secondMax)
{
secondMax = array[i];
}
if (array[i]>firstMax)
{
secondMax = firstMax;
firstMax=array[i];
}
}
cout << secondMax;
return 0;
}