Where should you begin?
Once the inputs, processes and outputs are clear, the code no longer begins as a blank page.
The IPO plan already tells you what must happen. Your job is to translate each part into code in a sensible order.
Learn how to turn a clear IPO plan into structured pseudocode one stage at a time.
Once the inputs, processes and outputs are clear, the code no longer begins as a blank page.
The IPO plan already tells you what must happen. Your job is to translate each part into code in a sensible order.
The calculator needs two numbers and one operator.
Each value must be stored so the program can use it later.
Number1 β INPUT "Enter the first number" Operator β INPUT "Enter an operator" Number2 β INPUT "Enter the second number"
REPEAT
Operator β INPUT "Enter +, -, * or /"
UNTIL Operator = "+" OR Operator = "-" OR
Operator = "*" OR Operator = "/"The operator decides which calculation runs, so this process needs selection.
IF Operator = "+"
THEN
Result β Number1 + Number2
ELSEIF Operator = "-"
THEN
Result β Number1 - Number2
ELSEIF Operator = "*"
THEN
Result β Number1 * Number2
ELSE
Result β Number1 / Number2
ENDIFA value appears, but the user may not know what it represents.
The message gives the value meaning.
Store the two numbers and the operator.
Only allow recognised operators.
Use selection to perform the correct calculation.
Display the result with a clear message.
// input the first number
Number1 β INPUT "Enter the first number"
// validate the operator
REPEAT
Operator β INPUT "Enter +, -, * or /"
UNTIL Operator = "+" OR Operator = "-" OR
Operator = "*" OR Operator = "/"
// input the second number
Number2 β INPUT "Enter the second number"
// perform the selected calculation
IF Operator = "+"
THEN
Result β Number1 + Number2
ELSEIF Operator = "-"
THEN
Result β Number1 - Number2
ELSEIF Operator = "*"
THEN
Result β Number1 * Number2
ELSE
Result β Number1 / Number2
ENDIF
// output the result
OUTPUT "The result is: ", ResultWhy is INPUT "Enter a number" incomplete if the value is not stored in a variable?