please help debug and explain // This program counts how many sales are made //
ID: 3714506 • Letter: P
Question
please help debug and explain
// This program counts how many sales are made
// in each of five categories of products
start
Declarations
num category
num SIZE = 5
num QUIT = 9
num sales[SIZE] = 0, 0, 0, 0, 0
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
output "Enter category ", QUIT, " to quit "
input category
while category = QUIT
if category > 1 AND category < SIZE then
sales[category - 1] = sales[category - 1] + 1
else
output "Invalid category"
endif
endwhile
output HEAD1
output HEAD2
while category < SIZE
output category + 1, sales[category]
category = category + 1
endwhile
stop
Explanation / Answer
Dear,
Modified is highlighted with red font
start
Declarations
num category
num SIZE = 5
num QUIT = 9
num sales[category] = 0, 0, 0, 0, 0
housekeeping()
while category = QUIT
mainLoop()
endwhile
endOfJob()
stop
housekeeping()
output "Enter category ", QUIT, " to quit "
input category
return
mainLoop()
if category >= 1 AND category <= SIZE then
sales[category - 1] = sales[category-1] + 1
else
output "Invalid category"
endif
housekeeping()
return
endOfJob()
Declarations
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
string categoryName[SIZE] = "Infants", "Children", "Teens", "Men", "Women"
output HEAD1
output HEAD2
num loop=0
while category < SIZE
output categoryName[loop], sales[loop]
loop =loop+ 1
endwhile
return
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.