S.A. pg. 213 #1-5, A.W. 1, 2, 7, 8
P.E. pg. 214 #1, 3, 4
S.W.
1. It makes the program easier to read and debug.
2. A pretest loop tests its condition before performing an iteration; while a post-test loop tests its condition after an iteration.
3. A loop that uses a true/false condition to control the number of iterations.
4. A loop that iterates a specific number of times.
5. Initialization, test, and increment
A.W.
1. Declare Integer num
Declare Integer product = 0
While product < 100 Display “Enter a number to be multiplied by 10” Input num Set product = num * 10 Display product
End While
2. Declare Integer num1
Declare Integer num2
Declare Integer sum
3. Declare String condition
Do
Display “Enter first number to be added” Input num1 Display “Enter second number to be added” Input num2 Set sum = num1 + num2 Display “The sum is “ & sum Set sum = 0 Display “Would you like to add another set of numbers, yes or no?” Input condition
While condition == “yes”
7. Declare integer x
Do
Display “Enter a number” Input x
While x > 0
8. Declare String sure = “n”
While sure != “y” and sure != “Y” Display “Are you sure you want to quit?” Input sure
End While
P.E.
1. Declare Integer bugs
Declare Integer day
Declare Integer total = 0
For day = 1 to 7 Display “Enter the amount of bugs collected from Day “ & day Input bugs total = total + bugs bugs = 0
End For
Display “The total amount of Bugs for the week is “ & total
3. Declare Double budget
Declare Double total = 0
Declare Double expense
Declare String keepGoing
Declare Double balance
Display “What is your budget for the month?”
Input budget
Do
Display “Enter an expense from the month” Input expense total = total + expense Display “The total expense so far is “ & total Display “Anymore expenses, y or n?” Input keepGoing
While keepGoing == “y”
Set balance = budget –