I found this somewhere on some website. Would you care to decode it, like explain why, when, and how they used the codes? The only part I didn't get is how did they get "largest_1" and "largest_2" by doing this. I see that it loops to find it but does the program overrides the "largest" numbers? This would help me understand more about finding the max/min of an assignment.
do
{
restart = false;
for ( i = 1; i < 4; i++ )
{
if ( input[i] < input[i+1] )
{
temp = input[i]; //=======================================//
input[i] = input[i+1]; //set up to do loop again until it's true//
input[i+1] = temp; //=======================================//
restart = true; // if it is true then it will go to while loop
} // end of If loop
} // end of For loop
} // end of Do loop
while ( restart == true ); // start of while loop
largest_1 = input[1]; // records first largest
largest_2 = input[2]; // records second largest
// desplays the answers
cout << "The largest two of the numbers you entered are " << largest_1
<< " and " << largest_2 << endl << endl;
return largest_1, largest_2;
}
Thank you.