Share
Explore BrainMass

Correct the program.

// Program accepts a student's year in school (1 to 4)
// and the number of cans collected for a recycling drive.
// Output is a report that lists each class year and
// the total number of cans collected by that class.
start
num year
num cans
num SIZE = 4
num collected[SIZE] = 0, 0, 0
string HEAD1 = "Can Recycling Report"
string HEAD2 = "Year Cans Collected"
input year, cans
while not eof
collected[year] = collected[year - 1] + cans
input year, cans
endwhile
print HEAD1
print HEAD2
year = 1
while year <= year
output year, collected[year - 1]
endwhile
stop

Solution Preview

Please find my comments, marked with #, inserted in your program below, along with the corrections. Kindly compare the following corrected program with your original program in case you are not clear about what is corrected (though # comments should make it clear anyway).

// Program accepts a student's year in school (1 to 4)
// and the number of cans collected for a recycling drive.
// Output ...

Solution Summary

Comments are inserted around the corrections to explain what was corrected and the need for that.

$2.19