I need help with debug

Debug06-02
// Program lets user input scores on four tests
// Average is computed and letter grade is determined
// Letter grades are based on 90 for an A, 80 for a B, and so on
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
num QUIT = "ZZZZZ"
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
num total
num average
num sub
output "Enter student name or ", QUIT, " to quit "
input name
while name <> QUIT
sub = 0
while sub < NUM_TESTS
output "Enter score "
input score
total = total + score
endwhile
average = total / NUM_TESTS
sub = 0
while average < RANGES[NUM_TESTS]
sub = sub + 1
endwhile
letterGrade = GRADES[NUM_TESTS]
output name, letterGrade
output "Enter student name or ", QUIT, " to quit "
input name
endwhile
stop

There are a few issues with the given code. First, the variable "total" and "sub" should be initialized to 0 before the while loops. Also, the variable "average" should be reset to 0 at the beginning of each iteration of the outer while loop. Lastly, the variable "NUM_TESTS" is being used in place of the variable "sub" in the second while loop, which is incorrect.

Here is the corrected code with debug comments:

start
// Variable Declarations
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
num QUIT = "ZZZZZ"
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
num total = 0 // Initialize total to 0
num average
num sub = 0 // Initialize sub to 0

// Program Execution
output "Enter student name or ", QUIT, " to quit "
input name
while name <> QUIT
total = 0 // Reset total to 0 at the beginning of each iteration
sub = 0 // Reset sub to 0 at the beginning of each iteration

while sub < NUM_TESTS
output "Enter score "
input score
total = total + score
sub = sub + 1 // Increment sub by 1 in each iteration
endwhile

average = total / NUM_TESTS
sub = 0 // Reset sub to 0 before using it in the next while loop

while average < RANGES[sub] // Use 'sub' instead of 'NUM_TESTS'
sub = sub + 1
endwhile

letterGrade = GRADES[sub] // Use 'sub' as an index for GRADES array
output name, letterGrade

output "Enter student name or ", QUIT, " to quit "
input name
endwhile

stop

The code you provided seems to be a program that lets the user input scores on four tests, computes the average, and determines the letter grade based on that average. However, there are a few issues with the code that need to be debugged. Let's go through the code step by step to identify and fix these issues.

1. The line `num QUIT = "ZZZZZ"` is incorrect. The variable `QUIT` should be of type string, not num. Change it to `string QUIT = "ZZZZZ"` to fix the error.

2. There is no initialization for the variable `total`. Add `total = 0` before the inner while loop to initialize it.

3. In the inner while loop, the variable `score` is not being incremented. Add `score = score + 1` after calculating the total.

4. Inside the second while loop, the condition `average < RANGES[NUM_TESTS]` should be `average < RANGES[sub]` to iterate through the `RANGES` array correctly.

5. The line `letterGrade = GRADES[NUM_TESTS]` is incorrect. It should be `letterGrade = GRADES[sub]` to assign the correct letter grade based on the determined range.

Once these fixes are made, the code should run without any errors. Remember to also initialize the variables `total`, `average`, and `sub` to the appropriate values based on your program logic.

If you need debug help, please

1. specify the compiler/language
2. supply error messages you got when the programme was executed or compiled.
3. indicate if it is a compilation, execution or logical error.

This one looks fishy:
output "Enter student name or ", QUIT, " to quit "

probably should read
output "Enter student name or QUIT to quit "

here:
while sub < NUM_TESTS
output "Enter score "
input score
total = total + score
endwhile

will run forever unless you increment sub.

while sub < NUM_TESTS
output "Enter score "
input score
total = total + score
sub=sub+1
endwhile

letterGrade = GRADES[NUM_TESTS]
means you'll always get an F.
I suggest
letterGrade = GRADES[sub]

Good luck!