So here is the code to my current inputs for getting the max capacity and the three weights:
$maxW = readline('Enter the maximum capacity: ');
$wei = readline('Enter the three weights: ');
Here is a loop for getting the max two numbers:
$array = array_map('intval',explode(" ", $wei));
$max=$max2=0;
for ($i = 0; $i < count($array); $i++){
if($i==0){
$max2 = $array[$i];
}
if($array[$i] > $max){
$max = $array[$i];
}
if($max > $array[$i] && $array[$i] > $max2){
$max2 = $array[$i];
}
}
echo "The two weights are " . $max . "and " . $max2;
Where did I mess up?
My real output should be this:
Enter the Maximum capacity: 10
Enter the three weights: 5 3 4
The Two weights are 5 and 4.