Win a copy of Functional Reactive Programming this week in the Other Languages forum!

logical error

Syamsul Hussin
Ranch Hand
Posts: 59
hi, this is my school's past year exam question, i can't spot the error.Can anyone point it out to me. thanks.
---------

The method given below is intended to find the number that is the minimum of all the numbers in
the Vector v that are larger than the minimum of the elements in v. You may assume that v contains
at least two elements, and that that the first two elements are different numbers.

i. Describe a vector of Integers that will give the correct result using the above method.
[2 marks]
ii. Describe a vector of Integers that will give incorrect results using the above method.
[2 marks]
iii. Outline how you would go about repairing the fault in the program so it would give correct
results with both your tests. [2 marks]
[ October 26, 2006: Message edited by: Syamsul Hussin ]

Syamsul Hussin
Ranch Hand
Posts: 59
oops, i've just spotted it, its the else if statement inside the for loop will not be executed if the the first if statement inside the for loop is not executed.. right?

Joel McNary
Bartender
Posts: 1840
If your minimum number is duplicated: i.e., {8, 9, 10, 8} the function will return 8 instead of 9. (The instructions only state that the first two elements are different; it says nothing about the uniqueness of these numbers)
The else if has nothing to do with it, me thinks. It gives the same result
[ May 22, 2003: Message edited by: Joel McNary ]

Syamsul Hussin
Ranch Hand
Posts: 59
right! thanks!