You are on page 1of 3

Find The Bugs Chapter 6

Each of the following pseudocode segments contains one or more bugs that you must find and
correct

1 This application prints a summary report for an aluminum can recycling drive at a high school.
When a student brings in cans, a user enters the student's year in school (1, 2, 3, or 4) and the
number of cans submitted. After all the data has been entered, a report lists each of the four
grades and the total number of cans recycled for each grade.

start
declare variables
int year
int cans
int SIZE = 4
int collected[SIZE] = 0, 0, 0, 0
string HEAD1 = "Can Recycling Report"
string HEAD2 = "Year Cans Collected"
get year, cans
while not eof
collected[year] = collected[year] + cans
endwhile
display HEAD1
display HEAD2
while year <= SIZE
display year, collected[year]
year = year + 1
endwhile
stop

2. This application prints a report that lists students and their course grades. A user enters each
student's name, and four test scores. The program calculates an average from the scores and
prints a report that contains each student's name and a letter grade based on the following scale:
90-100 A
80-89 B
70-79 C
60-69 D
59 and below F
Note that the average is the total of all the scores added together divided by the number of tests
taken, assuming all the tests are worth the same value and have the same total possible points.

start
declare variables
string name
int score
int NUMTESTS = 4
int NUMRANGES = 5
int RANGES[NUMRANGES] = 90, 80, 70, 60, 0
string GRADES[NUMRANGES] = "A", "B", "C", "D", "F"
int total = 0
int average
int sub
get name
while not eof
sub = 0
while sub < NUMTESTS
get score
total = total + score
sub = sub + 1
endwhile
average = total / NUMRANGES
sub = 0
while average < RANGES[NUMRANGES]
sub = sub + 1
endwhile
letterGrade = GRADES[NUMRANGES]
display name, letterGrade
get name
endwhile
stop

3.
This program should count how many sales are made in each of 5 categories of products and
continue until the user enters N when asked to add another sale.

start
declare variables
int category
int SIZE = 5
int sales[SIZE] = 0, 0, 0, 0, 0
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
display "Do you want to add another sale? (Y or N)"
get repeat
if repeat = Y
input category
if category >= 1 OR category <= SIZE then
sales[category] = sales[category] + 1
else
display "Invalid category"
endif
display "Do you want to add another sale? (Y or N)"
get repeat
endif
display HEAD1
display HEAD2
category = 0
while category = SIZE
display category + 1, sales[category]
category = category + 1
endwhile
stop

You might also like