• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

logical error

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Syamsul Hussin
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
right! thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic