While Loops
While Loops
While Loops
<>
QUESTION 2
A teacher wants to write a computer program to test
knowledge of Mathematics. Create algorithm (pseudocode and
flowchart) that sets out the following sequence of instructions.
Output what is 56+98?
Input an answer
If the correct answer is inputted, say “Yes, well done and stop”.
Otherwise,’ “No, try again” and repeat the action.
PSEUDOCODE
Start
Declare answer, ans_wer as integer
Print “Please enter your answer”
read answer
Ans_wer= 98 + 56
While ans_wer <> answer
Print “ No, try again”
Read answer
Endwhile
Output ‘Yes, Well done’
Stop
QUESTION 3 - HOMEWORK
Write algorithm (pseudocode and flowchart) to
calculate and print the average of 3 scores for a
number of students terminated by 9.
PLEASE NOTE
Example a bank will pay out money to a customer until his account is empty. We do
not know how many times he can withdraw money but we know when it will stop.
This means that when you are using a WHILE loop
If the test is true, the loop will continue