Introduction to Computer Programming - 99 Bottles Program - Homework 2 | CPS 196, Assignments of Computer Science

Material Type: Assignment; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 08/09/2009

koofers-user-3xl
koofers-user-3xl 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 2 Review:
Program Steps for the 99 Bottles Program:
Version 1: prints the last n verses
Get the number of verses from the user
Loop over the verses with the index ranging from the user’s number down to 1,
decrementing by 1
if it’s not the last verse,
Print the verse corresponding to the loop index, using index and index -1
else it is the last verse,
Print the special last verse using 1.
Version 2: prints the first n verses
Get the number of verses from the user
Initialize bottles to 99.
Loop while the verses are greater than 0.
If there is 1 bottle of beer left
Output the modified last verse.
else
Output the first half of the verse.
Subtract 1 from the bottles remaining.
Output the second half of the verse.
End if
Subtract 1 from the number of verses remaining

Partial preview of the text

Download Introduction to Computer Programming - 99 Bottles Program - Homework 2 | CPS 196 and more Assignments Computer Science in PDF only on Docsity!

Homework 2 Review:

Program Steps for the 99 Bottles Program:

Version 1: prints the last n verses

Get the number of verses from the user Loop over the verses with the index ranging from the user’s number down to 1, decrementing by 1 if it’s not the last verse, Print the verse corresponding to the loop index, using index and index - else it is the last verse, Print the special last verse using 1.

Version 2: prints the first n verses

Get the number of verses from the user Initialize bottles to 99. Loop while the verses are greater than 0. If there is 1 bottle of beer left Output the modified last verse. else Output the first half of the verse. Subtract 1 from the bottles remaining. Output the second half of the verse. End if Subtract 1 from the number of verses remaining