Friday, June 19, 2026

Chapter 9 - Pseudocode Notes

1. Average Calculation

Total <-- 0
PRINT "Enter the number of values to average"
INPUT Number
FOR Counter <-- 1 TO Number
    PRINT "Enter value"
    INPUT Value
    Total <-- Total + Value
NEXT Counter
Average <-- Total/Number
PRINT "The average of", Number, "values is", Average

2. Basic Operations & String Handling

INPUT StudentName
OUTPUT "You have made an error"
Counter <-- 1
Counter <-- Counter + 1
MyChar <-- "A"
LetterValue <-- ASC(MyChar)
StudentMark <-- 40
Percentage <-- (StudentMark/80) * 100
OldString <-- "Your mark is"
NewString <-- OldString & "ninety-seven"

Operators:

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • & String concatenation
  • <-- Assignment

3. IF Statement (Single Condition)

IF MyValue > YourValue THEN
    OUTPUT "I win"
ENDIF

4. IF…ELSE Statement

IF MyValue > YourValue THEN
    OUTPUT "I win"
ELSE
    OUTPUT "You win"
ENDIF

5. CASE Statement (No Otherwise)

CASE OF Direction
 "N": Y <-- Y + 1
 "S": Y <-- Y - 1
 "E": X <-- X + 1
 "W": X <-- X - 1
ENDCASE

6. CASE Statement (With Otherwise)

CASE OF Direction
 "N": Y <-- Y + 1
 "S": Y <-- Y - 1
 "E": X <-- X + 1
 "W": X <-- X - 1
 OTHERWISE: OUTPUT "Error"
ENDCASE

Relational Operators:

  • = Equal to
  • <> Not equal to
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to

7. FOR Loop (Summation)

Total <-- 0
FOR Counter <-- 1 TO 10
    OUTPUT "Enter a number"
    INPUT Number
    Total <-- Total + Number
NEXT Counter
OUTPUT "The total is", Total

8. REPEAT…UNTIL Loop (Positive Number)

REPEAT
    OUTPUT "Please enter a positive number"
    INPUT Number
UNTIL Number > 0

9. WHILE Loop (Negative Number)

Number <-- 0
WHILE Number >= 0 DO
    OUTPUT "Please enter a negative number"
    INPUT Number
ENDWHILE

10. REPEAT…UNTIL with AND Condition

REPEAT
    OUTPUT "Please enter a positive number less than fifty"
    INPUT Number
UNTIL (Number > 0) AND (Number < 50)

11. Validated Average Calculation

Total <-- 0
REPEAT
    PRINT "Enter the number of values to average"
    INPUT Number
UNTIL (Number > 0) AND (Number = INT(Number))
FOR Counter <-- 1 TO Number
    REPEAT
        PRINT "Enter an integer value"
        INPUT Value
    UNTIL Value = INT(Value)
    Total <-- Total + Value
NEXT Counter
Average <-- Total/Number
PRINT "The average of", Number, "values is", Average

12. Marathon Time Conversion

OUTPUT "Enter the time you took to run the marathon"
OUTPUT "Enter hours"
INPUT MarathonHours
OUTPUT "Enter minutes"
INPUT MarathonMinutes
OUTPUT "Enter seconds"
INPUT MarathonSeconds
TotalMarathonTimeSeconds <-- (MarathonHours * 3600) + (MarathonMinutes * 60) + MarathonSeconds
OUTPUT "Time for marathon in seconds", TotalMarathonTimeSeconds

No comments:

Folk Arts of India

Madhubani Painting   - Region: Mithila, Bihar   - Period: Ancient (references from Ramayana)   - Artists: Traditionally, women   - Themes...