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

turn this code into a desk check pls. start Declarations num x num average strin

ID: 3716890 • Letter: T

Question

turn this code into a desk check pls.

start

Declarations

num x

num average

string doContinue

num LENGTH = 6

num numbers[LENGTH]

doContinue = “Y”

while doContinue = “Y”

x = 1

while x < LENGTH

output “Enter a number”

input numbers[x]

x = x + 1

endwhile

average = calcAverage(numbers, LENGTH)

x = 0

while x < LENGTH

output numbers[x], average – numbers[x]

x = x + 1

endwhile

output “Would you like to continue (Y/N)?”

input doContinue

endwhile

stop

num calcAverage(num[] vals, num size)

Declarations

num x

num avg

num sum

sum = 0

x = 0

while x < size

sum = sum + vals[x]

x = x + 1

endwhile

avg = sum / size

return avg

Explanation / Answer

Desk checking is informal manual testing done by the programmer to verify the code and logic of algorithm. it is done by making the table.

Summary of this code: there is one issue regrading initlaization of variable x . at some place it is initalized with 0 and some palce with 1. So you should initialized x with either 0 or 1 at all place in code and function.

In detail:

--------------------------------------------------------------------------------------------------------------------------------------------------------

we add line number at the start of each line.

1 start
2 Declarations
3 num x
4 num average
5 string doContinue
6 num LENGTH = 6
7 num numbers[LENGTH]
8 doContinue = “Y”
9 while doContinue = “Y”
10 x = 1
11 while x < LENGTH
12 output “Enter a number”
13 input numbers[x]
14 x = x + 1
15 endwhile
16 average = calcAverage(numbers, LENGTH)
17 x = 0
18 while x < LENGTH
19 output numbers[x], average – numbers[x]
20 x = x + 1
21 endwhile
22 output “Would you like to continue (Y/N)?”
23 input doContinue
24 endwhile
25 stop

Errors: at 17th line x should be initialized with 1 not with zero.

stop code

---------------------------------------------------------------------------------------------------------------------------------------------------

1 num calcAverage(num[] vals, num size)
2 Declarations
3 num x
4 num avg
5 num sum
6 sum = 0
7 x = 0
8 while x < size
9 sum = sum + vals[x]
10 x = x + 1
11 endwhile
12 avg = sum / size
13 return avg

Error: again here in this function at line no 7 x will be initialized with 1.

Line Number Processing Input/Output 1,2,3,4,5,6,7,8 variable declare and initailization 9 loop started 10 x initailed to 1 11 2nd while loop started for x < LENGTH 12,13 input from user input numbers[1] :12 14 increment x x=2 x=2 15 loop countines 12,13 input from user input numbers[2] :1 14,15 incrment x and loop continue x=3 12,13 input from user input numbers[3] :10 14,15 incrment x and loop continue x=4 12,13 input from user input numbers[4] 2 14,15 incrment x and loop continue x=5 12,13 input from user input numbers[5] :3 14,15 incrment x and loop continue x=6 11 loop condtion false ,go to 16th line 16 avegrae cal fun called get avg as output 17 x initialized to 0 18 loop started x<length 19 try to print numbers[0] :will give garbage value garbage output for x=0 20 incrment x x=1 21 loop contiue for 6 time x=0,1,2,3,4,5 22 print sg on screen 23 input from user input in doContinue char variable. 24 if doContinue is "Y" ,whole process start from line number 9 again. otherwise loop stop 25

stop code