Exercise Set 09 SOLUTIONS
1. Write a while loop that lets the user enter a number. The number should
be multiplied by 10, and the result stored in a variable named product.
The loop should run as long as product contains a value less than 100.
Integer num
Integer product = 0
while product < 100
Input num
product = num * 10
endwhile
2. Write a do while loop that asks the user to enter two numbers. The
numbers should be added and the sum displayed. The loop should ask
the user whether they wish to perform the operation again. If so, the
loop should repeat; otherwise it should end.
Integer num1
Integer num2
String response
do
Input num1
Input num2
sum = num1 + num2
Print “Perform operation again?”
Input response
while response == “Yes”
3. Write a for loop that displays the integers from 1 to 30.
Integer count
for count = 1 to 30
Print count
endfor
4. Write a for loop that asks the user to enter a number. The loop should run
10 times and keep a running total of the numbers entered.
Float num
Float sum
Integer count
for count = 1 to 10
sum = sum + num
endfor
5. Write a sentinel controlled while loop that asks the user to enter an age as
an integer. The loop should run keep a running total of the ages entered.
The loop must end when the user enters a negative number as the age.
Integer age
Integer tot = 0
Input age
while age >=0
tot = tot + age
Input age
endwhile