
Mihir P. answered 07/10/23
Computer Science Tutor for High School and College Students
Your mistake is that you use an else statement if the element at index i is not less than the current lowest value. For example, when i=2, lowest is 2 and highest is 7. num[2] is 6, which is less than 7. However, in your code, because 6 is not less than 2, you set highest to 6, which is incorrect.
You can fix this by simply changing the else statement to another conditional expression that sees if the value at i is greater than the current highest.