Forums Register Login

logical error

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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)
(Edit begins here, after I saw your reply)
The else if has nothing to do with it, me thinks. It gives the same result
[ May 22, 2003: Message edited by: Joel McNary ]
+Pie Number of slices to send: Send
right! thanks!
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 819 times.
Similar Threads
Array problem
Threads
How to read and wrire date in RMS
Cameron's SCJA Mock Exam Question (pg.200, 9-4)
Help with adding elements to vector
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:26:25.