Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help debugging this problem. // This application reads 10 numbers // and

ID: 3545735 • Letter: I

Question

I need help debugging this problem.


// This application reads 10 numbers

// and sorts them, and displays the three highest numbers

start

   Declarations

      num SIZE = 10

      num number

      num numbers[SIZE]

      num count

   getReady()

   while count < SIZE

      detailLoop()

   endwhile

   finish()

stop


getReady()

   output "Enter a number "

   input number

return


detailLoop()

   numbers[SIZE] = number

   count = count + 1

   output "Enter a number "

   input number

return


finish()

   sort()

   output "The highest three are ", numbers[0], numbers[0], numbers[0]

return


sort()

   num x = 0

   num y = 0

   num COMPS = count - 1

   while y < COMPS

      x = 0

      while x < COMPS

         if numbers[x] < numbers[x + 1] then

            swap()

         endif

         x = x + 1

      endwhile

      y = y + 1

   endwhile

return


swap()

   num temp

   temp = numbers[x + 1]

   numbers[x + 1] = numbers[x]

   numbers[x] = temp

return



Explanation / Answer

Correction in the function detailLoop()


detailLoop()

numbers[count] = number ...............................//The array index must be count and not SIZE

count = count + 1

output "Enter a number "

input number

return


______________________________________________________________________________________________


Corrections in sort() function


sort()

num x = 0

num y = 0

num COMPS = count - 1

while y < COMPS

x = y + 1.....................................// In selection-sort the inner loop variable always starts at one value more than the outer-loop variable

while x < COMPS

if numbers[x] < numbers[x + 1] then

swap()

endif

x = x + 1

endwhile

y = y + 1

endwhile

return


______________________________________________________________________________________________


finish()

sort()

output "The highest three are ", numbers[0], numbers[1], numbers[2] ............................// First three elements of the array

return



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote