0% found this document useful (0 votes)
2 views57 pages

NADF511 StudyNotesAndExamples Ch4to7

The NADF 511 study guide covers chapters 4 to 7, focusing on problem-solving techniques, including the selection control structure, relational and logical operators, and the simple IF statement. It provides examples and pseudocode for various scenarios, such as discounts, pass/fail evaluations, and wage calculations. The guide emphasizes the importance of data validation and includes trace tables to illustrate the flow of logic in programming.

Uploaded by

mananahangy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views57 pages

NADF511 StudyNotesAndExamples Ch4to7

The NADF 511 study guide covers chapters 4 to 7, focusing on problem-solving techniques, including the selection control structure, relational and logical operators, and the simple IF statement. It provides examples and pseudocode for various scenarios, such as discounts, pass/fail evaluations, and wage calculations. The guide emphasizes the importance of data validation and includes trace tables to illustrate the flow of logic in programming.

Uploaded by

mananahangy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

NADF 511
Applications Development Foundations
Comprehensive Study Guide
Chapters 4 – 7 | Problem Solving · IPO · Pseudocode · Trace Tables
Sol Plaatje University | 2026

Sol Plaatje University | Page 1 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

CHAPTER 4: The Selection Control Structure – Part 1


📌 This chapter covers: Relational operators, Logical operators, Simple IF, IF-THEN-ELSE,
Compound IF, Boolean variables, and Data validation. Algorithms test a condition and follow
different paths depending on whether the result is TRUE or FALSE.

4.1 Relational Operators


Relational operators compare two values and always yield a Boolean result (TRUE or FALSE).
Mathematical operators have higher priority than relational operators.

Symbol Meaning Example


= Equal to A = 5
< Less than number < 97
> Greater than total > 100
<= Less than or equal to students <= 50
>= Greater than or equal to weight >= 75
<> Not equal to quantity <> 17

Relational Operator Examples (10)


EXAMPLE 1: Is 5 > 3 true?
✓ ANSWER: TRUE – 5 is greater than 3

EXAMPLE 2: Is 16 = 5 true?
✓ ANSWER: FALSE – 16 does not equal 5

EXAMPLE 3: b <= a – 3, where b = 5, a = 7


✓ ANSWER: 5 <= 4 → FALSE

EXAMPLE 4: m + 7 > n – 3 * p, where m=4, n=12, p=5


✓ ANSWER: 11 > –3 → TRUE

EXAMPLE 5: mark >= 50, where mark = 45


✓ ANSWER: 45 >= 50 → FALSE (student failed)

Sol Plaatje University | Page 2 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

EXAMPLE 6: mark >= 50, where mark = 72


✓ ANSWER: 72 >= 50 → TRUE (student passed)

EXAMPLE 7: salary > 3000, where salary = 2800


✓ ANSWER: 2800 > 3000 → FALSE (no tax)

EXAMPLE 8: number <> 17, where number = 20


✓ ANSWER: 20 <> 17 → TRUE

EXAMPLE 9: hours <= 40, where hours = 40


✓ ANSWER: 40 <= 40 → TRUE

EXAMPLE 10: age < 12, where age = 15


✓ ANSWER: 15 < 12 → FALSE (full price)

Sol Plaatje University | Page 3 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

4.2 Logical Operators


📌 Logical operators join Boolean expressions. Priority: NOT (1st) → AND (2nd) → OR (3rd).
Mathematical operators are processed first, then relational, then logical.

Operator Rule Truth Table


NOT Yields the opposite of the value NOT TRUE=FALSE | NOT
FALSE=TRUE

AND BOTH must be TRUE to yield TRUE T AND T=T | T AND F=F | F
AND F=F

OR AT LEAST ONE must be TRUE T OR T=T | T OR F=T | F


OR F=F

Logical Operator Examples (10)


EXAMPLE 1: TRUE AND TRUE
✓ ANSWER: TRUE – both are TRUE

EXAMPLE 2: TRUE AND FALSE


✓ ANSWER: FALSE – not both TRUE

EXAMPLE 3: FALSE OR TRUE


✓ ANSWER: TRUE – at least one is TRUE

EXAMPLE 4: NOT TRUE


✓ ANSWER: FALSE – opposite of TRUE

EXAMPLE 5: D OR K AND NOT S where D=TRUE, K=FALSE, S=TRUE


✓ ANSWER: TRUE OR FALSE AND FALSE = TRUE OR FALSE = TRUE

EXAMPLE 6: M > 7 AND D < S^2 where M=7, D=8, S=4


✓ ANSWER: FALSE AND TRUE = FALSE

EXAMPLE 7: age >= 18 AND licensed where age=20, licensed=TRUE


✓ ANSWER: TRUE AND TRUE = TRUE (may drive)

EXAMPLE 8: grade = 'C' OR years > 5 where grade='A', years=7

Sol Plaatje University | Page 4 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

✓ ANSWER: FALSE OR TRUE = TRUE (gets bonus)

EXAMPLE 9: NOT FALSE OR FALSE


✓ ANSWER: TRUE OR FALSE = TRUE

EXAMPLE 10: (15/3 = 5) AND (8+2 = 11) [from test Q1.17]


✓ ANSWER: TRUE AND FALSE = FALSE

Sol Plaatje University | Page 5 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

4.3 The Simple IF Statement


📌 A simple IF tests one condition. If TRUE, the body executes; if FALSE, the body is
SKIPPED entirely. Syntax: if condition then statement(s) endif

Syntax:
if condition then
statement(s)
endif

Simple IF Examples with IPO, Pseudocode & Trace Table (10)


EXAMPLE 1: Pencil Discount – John buys 25+ pencils → 7.5% discount
Problem: Enter number of pencils and price. If 25 or more pencils, apply 7.5% discount. Display amount
due.
IPO Chart:
INPUT PROCESSING OUTPUT
number (Integer) Prompt & enter number, price amount (Real)
price (Real) Calculate amount = number ×
price
If number >= 25: apply 7.5%
discount
Display amount

Pseudocode:
CalcAmount
display "Number of pencils bought?"
enter number
display "Price of one pencil?"
enter price
amount = number * price
if number >= 25 then
amount = amount - (amount * 0.075)
endif
display "Amount due: R ", amount
end

Trace Table (number=30, price=R2.25):


Instruction number price amount Output
display Number of
pencils?
enter 30

display Price?

enter 30 2.25

Sol Plaatje University | Page 6 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

calculate 30 2.25 67.50

if (30>=25) TRUE

calculate 30 2.25 62.44

display Amount due:


R62.44

EXAMPLE 2: Student Pass/Fail – Mark >= 50 → passed, else failed


Problem: Enter student mark. If >= 50 display 'pass', else display 'fail'.
IPO Chart:
INPUT PROCESSING OUTPUT
mark (Integer) Prompt & enter mark mark
Initialise message = 'pass' message (String)
If mark < 50: message = 'fail'
Display mark and message

Pseudocode:
PrepareResult
display "Enter mark: "
enter mark
message = "pass"
if mark < 50 then
message = "fail"
endif
display "Mark: ", mark, " Result: ", message
end

Trace Table (mark=45):


Instruction mark message Output
display Enter mark:

enter 45

assign 45 pass

if (45<50) TRUE

assign 45 fail

display Mark: 45 Result:


fail

EXAMPLE 3: Overtime Bonus – Hours > 45 → add R300 bonus


Problem: If employee worked more than 45 hours, add R300 to wage.
IPO Chart:

Sol Plaatje University | Page 7 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

INPUT PROCESSING OUTPUT


hours (Integer) Enter hours and wage wage (Real)
wage (Real) If hours > 45: wage = wage +
300
Display wage

Pseudocode:
CalcWage
display "Hours worked?"
enter hours
display "Basic wage?"
enter wage
if hours > 45 then
wage = wage + 300
endif
display "Total wage: R ", wage
end

Trace Table (hours=50, wage=900):


Instruction hours wage Output
enter 50

enter 50 900

if (50>45) TRUE

calculate 50 1200

display Total wage: R1200

EXAMPLE 4: Rent Surcharge – Distance < 50 km → 5% surcharge


Problem: Henry rents a trailer. Basic R200/day + R per km. If < 50 km, add 5% surcharge.
IPO Chart:
INPUT PROCESSING OUTPUT
days (Integer) Enter all values totalDue (Real)
kmRate (Real) cost = R200*days +
distance (Real) kmRate*distance
If distance < 50: surcharge =
cost*0.05
Display total

Pseudocode:
RentalCost
enter days, kmRate, distance
cost = 200 * days + kmRate * distance
if distance < 50 then

Sol Plaatje University | Page 8 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

cost = cost + cost * 0.05


endif
display "Amount due: R ", cost
end

Trace Table:
Instruction distance cost Output
enter 30

calculate 30 560

if (30<50) TRUE

calculate 30 588

display Amount due: R588

EXAMPLE 5: Cake Slice Price – Round up cents to next Rand


Problem: Lerato bakes cakes. Cost + 30% profit. Divide by 10 slices. Round up any cents to next full
Rand.
IPO Chart:
INPUT PROCESSING OUTPUT
expense (Real) Enter expense sliceInt (Integer)
cakePrice = expense +
expense*0.3
sliceInt = cakePrice \ 10
sliceDec = cakePrice / 10
If sliceInt <> sliceDec: sliceInt =
sliceInt+1

Pseudocode:
CalcCakePrice
display "Cost of cake?"
enter expense
cakePrice = expense + expense * 0.3
sliceInt = cakePrice \ 10
sliceDec = cakePrice / 10
if sliceInt <> sliceDec then
sliceInt = sliceInt + 1
endif
display "Price per slice: R ", sliceInt
end

Trace Table:
Instruction expense cakePrice sliceInt sliceDec Output
enter 18.60

Sol Plaatje University | Page 9 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

calc 24.18

calc 2

calc 2.418

if TRUE
(2<>2.418)
calc 3

display R3

EXAMPLE 6: Harry's Wages – Extra R10/hr for > 40 hours


Problem: Harry earns R16.50/hr. If hours > 40, extra R10/hr. Calculate total wages.
IPO Chart:
INPUT PROCESSING OUTPUT
hours (Real) Enter hours wage (Real)
wage = hours * 16.50
If hours > 40: extra = (hours-
40)*10, wage = wage+extra
Display wage

Pseudocode:
CalcWages
display "Hours worked?"
enter hours
wage = hours * 16.50
if hours > 40 then
wage = wage + (hours - 40) * 10
endif
display "Total wages: R ", wage
end

Trace Table:
Instruction hours wage Output
enter 45

calc 45 742.50

if (45>40) TRUE

calc 45 792.50

display R792.50

EXAMPLE 7: Entrance Fee – Numeric data validation


Problem: Enter hours and tariff. Validate that both are numeric before calculating wage.

Sol Plaatje University | Page 10 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

IPO Chart:
INPUT PROCESSING OUTPUT
hours (Real) Enter hours and tariff wage (Real)
tariff (Real) Validate: if numeric
Calculate wage = tariff * hours
Else: display error

Pseudocode:
ValidateAndCalc
display "Hours worked?"
enter hours
display "Tariff per hour?"
enter tariff
if hours is numeric AND tariff is numeric then
wage = tariff * hours
display "Wage: R ", wage
else
display "Invalid input values"
endif
end

Trace Table:
Instruction hours tariff wage Output
enter abc

enter 15.00

if (numeric?) FALSE

display Invalid input


values

EXAMPLE 8: Department Bonus – Dept 7 gets R550, others R500


Problem: Dumisane's department number determines bonus. Dept 7 → R550. All others → R500.
IPO Chart:
INPUT PROCESSING OUTPUT
grossSalary (Real) Enter salary and dept netIncome (Real)
deptNo (Integer) bonus = 500
If deptNo = 7: bonus = 550
grossIncome = grossSalary +
bonus
tax = grossIncome * 0.20
netIncome = grossIncome - tax

Pseudocode:
CalcNetIncome

Sol Plaatje University | Page 11 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

enter grossSalary, deptNo


bonus = 500
if deptNo = 7 then
bonus = 550
endif
gross = grossSalary + bonus
tax = gross * 0.20
netIncome = gross - tax
display "Net income: R ", netIncome
end

Trace Table:
Instruction deptNo bonus gross netIncome Output
enter 7

assign 7 500

if (7=7) TRUE

assign 7 550

calc 5550

calc 4440

display R4440

EXAMPLE 9: Pizza Split – Can Jessie and Sally afford pizza?


Problem: Enter pizza cost and each person's money. If combined >= cost, they can buy large pizza.
IPO Chart:
INPUT PROCESSING OUTPUT
cost (Real) Enter all values message (String)
jessie (Real) combined = jessie + sally
sally (Real) If combined >= cost: display
large pizza message
Else: display small pizza
message

Pseudocode:
PizzaDecision
enter cost, jessie, sally
combined = jessie + sally
if combined >= cost then
display "Buy the large pizza!"
else
display "Buy a small pizza."
endif
end

Sol Plaatje University | Page 12 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Trace Table:
Instruction combined cost Output
calc 75

enter 80

if (75>=80) FALSE

display Buy a small pizza.

EXAMPLE 10: Billy's Computers – Can all be loaded in one trip?


Problem: Enter total computers and vehicle capacity. If total > capacity, show how many still need
transport.
IPO Chart:
INPUT PROCESSING OUTPUT
total (Integer) Enter total and capacity message
capacity (Integer) If total > capacity: remaining = remaining (Integer)
total - capacity
Display message and remaining

Pseudocode:
ComputerTransport
enter total, capacity
if total > capacity then
remaining = total - capacity
display "Cannot transport all. Still need: ", remaining
else
display "All computers can be transported."
endif
end

Trace Table:
Instruction total capacity remaining Output
enter 20 15

if (20>15) TRUE

calc 5

display Still need: 5

Sol Plaatje University | Page 13 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

4.4 The IF-THEN-ELSE Statement


📌 IF-THEN-ELSE executes one block when TRUE, and a different block when FALSE. Every
path is covered. Syntax: if condition then / statements / else / other statements / endif

if condition then
statements when TRUE
else
statements when FALSE
endif

IF-THEN-ELSE Examples with IPO, Pseudocode & Trace Table (10)


EXAMPLE 1: Competition Winner – Compare Angelina vs Freedom's points
Problem: Enter points for both competitors. Display the winner's name and points.
IPO Chart:
INPUT PROCESSING OUTPUT
pointA (Integer) Enter both points winner (String)
pointF (Integer) If pointA > pointF: pointW (Integer)
winner=Angelina,
pointW=pointA
Else: winner=Freedom,
pointW=pointF
Display winner and pointW

Pseudocode:
DetermineWinner
enter pointA, pointF
if pointA > pointF then
winner = "Angelina"
pointW = pointA
else
winner = "Freedom"
pointW = pointF
endif
display "Winner: ", winner, " Points: ", pointW
end

Trace Table:
Instruction pointA pointF winner pointW Output
enter 175 179

if FALSE
(175>179)
assign Freedom 179

Sol Plaatje University | Page 14 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display Freedom 179

EXAMPLE 2: Dennis's Reading – Can he read 5 books in 14 holiday days?


Problem: Enter pages per book and pages per day. Calculate if 5 books can be read in 14 days.
IPO Chart:
INPUT PROCESSING OUTPUT
bookPages (Integer) Enter values bookDays (Real)
dayPages (Integer) bookDays = bookPages / message (String)
dayPages
days = bookDays * 5
If days <= 14: can read, else
cannot

Pseudocode:
ReadingSpeed
enter bookPages, dayPages
bookDays = bookPages / dayPages
days = bookDays * 5
if days <= 14 then
display "Can read 5 books!"
else
display "Cannot read 5 books."
endif
end

Trace Table:
Instruction bookPages dayPages bookDays days Output
enter 120 50

calc 2.4

calc 12

if (12<=14) TRUE

display Can read 5


books!

EXAMPLE 3: Salary Increase – Dept A gets 10%, others 8%


Problem: If employee is in Department A, salary increase = 10%. Otherwise increase = 8%.
IPO Chart:
INPUT PROCESSING OUTPUT
dept (String) Enter dept and salary salary (Real)
salary (Real) If dept = 'A': increase =
salary*0.1

Sol Plaatje University | Page 15 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Else: increase = salary*0.08


salary = salary + increase

Pseudocode:
CalcIncrease
enter dept, salary
if dept = "A" then
increase = salary * 0.1
else
increase = salary * 0.08
endif
salary = salary + increase
display "New salary: R ", salary
end

Trace Table:
Instruction dept salary increase Output
enter B 24000

if ('B'='A') FALSE

calc 1920

calc 25920

display R25920

EXAMPLE 4: Income Tax – Full-time 29.5%, Part-time 25%


Problem: Enter annual salary and employment type. Calculate monthly net salary after tax.
IPO Chart:
INPUT PROCESSING OUTPUT
anSalary (Real) Enter salary and type netMonthly (Real)
empType (String) monthlySalary = anSalary / 12
If full-time: tax = monthly * 0.295
Else: tax = monthly * 0.25
netMonthly = monthly - tax

Pseudocode:
CalcNetSalary
enter anSalary, empType
monthly = anSalary / 12
if empType = "full" then
tax = monthly * 0.295
else
tax = monthly * 0.25
endif

Sol Plaatje University | Page 16 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

net = monthly - tax


display "Net monthly: R ", net
end

Trace Table:
Instruction monthly empType tax net Output
calc 4000

enter full

if ('full') TRUE

calc 1180

calc 2820

display R2820

EXAMPLE 5: Soccer Tickets – 8+ tickets: R12.50 each, fewer: R15 each


Problem: Enter number of tickets. If >= 8, price is R12.50 each, else R15 each.
IPO Chart:
INPUT PROCESSING OUTPUT
numTickets (Integer) Enter tickets total (Real)
If numTickets >= 8: total =
numTickets * 12.50
Else: total = numTickets * 15
Display total

Pseudocode:
CalcTickets
enter numTickets
if numTickets >= 8 then
total = numTickets * 12.50
else
total = numTickets * 15
endif
display "Amount due: R ", total
end

Trace Table:
Instruction numTickets total Output
enter 10

if (10>=8) TRUE

calc 125.00

display R125.00

Sol Plaatje University | Page 17 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

EXAMPLE 6: Dog Weight – Display the heavier dog


Problem: Enter weight of Fluffy and Terry. Display the name of the heavier dog.
IPO Chart:
INPUT PROCESSING OUTPUT
fluffy (Real) Enter both weights message (String)
terry (Real) If fluffy > terry: display Fluffy
Else: display Terry

Pseudocode:
HeavierDog
enter fluffy, terry
if fluffy > terry then
display "Fluffy is heavier"
else
display "Terry is heavier"
endif
end

Trace Table:
Instruction fluffy terry Output
enter 8.5 12.0

if (8.5>12.0) FALSE

display Terry is heavier

EXAMPLE 7: Course Fees – Code A: R234/week, Code B: R287.50/week


Problem: Enter course code and weeks. Calculate total fee based on course code.
IPO Chart:
INPUT PROCESSING OUTPUT
courseCode (Char) Enter code and weeks total (Real)
weeks (Integer) If code = 'A': total = weeks * 234
Else: total = weeks * 287.50
Display total

Pseudocode:
CalcCourseFee
enter courseCode, weeks
if courseCode = "A" then
total = weeks * 234
else
total = weeks * 287.50

Sol Plaatje University | Page 18 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

endif
display "Total fee: R ", total
end

Trace Table:
Instruction courseCode weeks total Output
enter B 4

if ('B'='A') FALSE

calc 1150

display R1150

EXAMPLE 8: Mark Adjustment – > 47: increase 2.5%, else decrease 5.7%
Problem: Enter student mark. If mark > 47, increase by 2.5%. Otherwise decrease by 5.7%.
IPO Chart:
INPUT PROCESSING OUTPUT
mark (Real) Enter mark mark (Real)
If mark > 47: mark = mark *
1.025
Else: mark = mark * 0.943
Display new mark

Pseudocode:
AdjustMark
enter mark
if mark > 47 then
mark = mark * 1.025
else
mark = mark * 0.943
endif
display "New mark: ", mark
end

Trace Table:
Instruction mark (in) mark (out) Output
enter 40

if (40>47) FALSE

calc 37.72

display 37.72

EXAMPLE 9: Salary & Tax – Display if income tax is required

Sol Plaatje University | Page 19 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Problem: Enter employee salary. Only people earning > R3000/month pay tax.
IPO Chart:
INPUT PROCESSING OUTPUT
empSalary (Real) Enter salary message (String)
If empSalary > 3000: display tax
message
Else: display no tax message

Pseudocode:
TaxCheck
enter empSalary
if empSalary > 3000 then
display "Tax required"
else
display "No tax required"
endif
end

Trace Table:
Instruction empSalary Output
enter 2500

if (2500>3000) FALSE

display No tax required

EXAMPLE 10: Josie's Movie – Boolean: homework done AND has R10
Problem: Josie can go to movies if homework is done AND she has R10. Use a Boolean variable.
IPO Chart:
INPUT PROCESSING OUTPUT
homework (Boolean) Enter homework status and message (String)
money (Real) money
If homework AND money >= 10:
display 'Go to movies'
Else: display 'Stay home'

Pseudocode:
MoviePermission
enter homework, money
if homework AND money >= 10 then
display "You can go to the movies!"
else
display "Stay home."
endif
end

Sol Plaatje University | Page 20 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Trace Table:
Instruction homework money Output
enter TRUE 10

if (TRUE AND TRUE


10>=10)
display You can go to the
movies!

Sol Plaatje University | Page 21 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

4.5 Compound IF Statements


📌 Compound IF combines multiple conditions using AND/OR/NOT. • AND: BOTH conditions
must be TRUE • OR: AT LEAST ONE condition must be TRUE • Use parentheses to control
evaluation order

Compound IF Examples with IPO, Pseudocode & Trace Table (10)


EXAMPLE 1: Circus Entrance – Under 12 OR 60+ → 25% discount
Problem: Persons younger than 12 OR aged 60+ receive 25% discount on entrance fee.
IPO Chart:
INPUT PROCESSING OUTPUT
fee (Real) Enter fee and age actFee (Real)
age (Integer) If age < 12 OR age >= 60:
actFee = fee * 0.75
Else: actFee = fee
Display actFee

Pseudocode:
EntranceFee
enter fee, age
if age < 12 OR age >= 60 then
actFee = fee - fee * 0.25
else
actFee = fee
endif
display "Fee: R ", actFee
end

Trace Table:
Instruction fee age actFee Output
enter 50 9

if (9<12 OR TRUE
9>=60)
calc 37.50

display R37.50

EXAMPLE 2: Car Driver – Age >= 18 AND has licence → may drive
Problem: Person may drive only if aged 18+ AND has a driver's licence (Boolean).
IPO Chart:
INPUT PROCESSING OUTPUT

Sol Plaatje University | Page 22 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

age (Integer) Enter age and licensed message (String)


licensed (Boolean) If age >= 18 AND licensed:
display may drive
Else: display may not drive

Pseudocode:
DriverCheck
enter age, licensed
if age >= 18 AND licensed then
display "You may drive a car."
else
display "You may not drive a car."
endif
end

Trace Table:
Instruction age licensed Output
enter 20 TRUE

if (20>=18 AND TRUE


TRUE)
display You may drive a
car.

EXAMPLE 3: Grade C OR 5+ Years Service → R1000 bonus


Problem: Employee gets R1000 bonus if Grade C OR worked > 5 years.
IPO Chart:
INPUT PROCESSING OUTPUT
grade (Char) Enter grade and years bonus (Real)
years (Integer) If grade='C' OR years>5:
bonus=1000
Else: bonus=0
Display bonus

Pseudocode:
EmployeeBonus
enter grade, years
if grade = "C" OR years > 5 then
bonus = 1000
else
bonus = 0
endif
display "Bonus: R ", bonus
end

Sol Plaatje University | Page 23 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Trace Table:
Instruction grade years bonus Output
enter A 7

if ('A'='C' OR TRUE
7>5)
assign 1000

display R1000

EXAMPLE 4: Tebogo's Budget – Salary < R1800, split into categories


Problem: Enter monthly salary (< R1800). After R450 rent, split remainder: 50% food, 20% clothes,
15% transport, 5% charity, rest pocket money.
IPO Chart:
INPUT PROCESSING OUTPUT
salary (Real) Enter salary food
remainder = salary - 450 clothes
food = remainder * 0.50 transport
clothes = remainder * 0.20 charity
transport = remainder * 0.15 pocket
charity = remainder * 0.05
pocket = remainder - food -
clothes - transport - charity

Pseudocode:
TebogoBudget
display "Enter monthly salary (< R1800):"
enter salary
if salary < 1800 AND salary > 0 then
remainder = salary - 450
food = remainder * 0.50
clothes = remainder * 0.20
transport = remainder * 0.15
charity = remainder * 0.05
pocket = remainder - food - clothes - transport - charity
display "Food: R", food
display "Clothes: R", clothes
display "Transport: R", transport
display "Charity: R", charity
display "Pocket: R", pocket
else
display "Invalid salary entered"
endif
end

Trace Table:

Sol Plaatje University | Page 24 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Instruction salary remainder food clothes pocket Output


enter 1700

if (<1800 TRUE
AND >0)
calc 1250

calc 625

calc 250

calc 75

display Food:R625...

EXAMPLE 5: Tennis Court – Calculate Perimeter AND Area [from Sem Test]
Problem: Enter length and width of tennis court. Calculate and display perimeter and area.
IPO Chart:
INPUT PROCESSING OUTPUT
length (Real) Enter length and width perimeter (Real)
width (Real) perimeter = 2 * (length + width) area (Real)
area = length * width
Display perimeter and area

Pseudocode:
TennisCourt
display "Enter length in metres:"
enter length
display "Enter width in metres:"
enter width
if length is numeric AND width is numeric then
perimeter = 2 * (length + width)
area = length * width
display "Perimeter: ", perimeter, " m"
display "Area: ", area, " m²"
else
display "Invalid input"
endif
end

Trace Table:
Instruction length width perimeter area Output
enter 23.77 10.97

if TRUE
(numeric)
calc 69.48

Sol Plaatje University | Page 25 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

calc 260.85

display 69.48m |
260.85m²

EXAMPLE 6: Gym Membership – Member R8, Non-Member R12


Problem: Enter student name and membership status (Boolean). Display name and entrance fee.
IPO Chart:
INPUT PROCESSING OUTPUT
stName (String) Enter name and member status stName
member (Boolean) If member: message = 'R8 fee' message
Else: message = 'R12 fee'
Display stName and message

Pseudocode:
GymEntry
enter stName, member
if member then
message = "must pay R8"
else
message = "must pay R12"
endif
display stName, " ", message
end

Trace Table:
Instruction stName member message Output
enter Sally Jones TRUE

if (TRUE) TRUE

assign must pay R8

display Sally Jones


must pay R8

EXAMPLE 7: Swim AND Cycle – Qualify for medal?


Problem: Participant must cycle >= 20 km AND swim >= 500 m to earn a medal.
IPO Chart:
INPUT PROCESSING OUTPUT
cycle (Real) Enter cycle distance and swim message (String)
swim (Real) distance
If cycle >= 20 AND swim >=
500: qualified
Else: not qualified

Sol Plaatje University | Page 26 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Pseudocode:
MedalCheck
enter cycle, swim
if cycle >= 20 AND swim >= 500 then
display "Qualified for medal!"
else
display "Not qualified."
endif
end

Trace Table:
Instruction cycle swim Output
enter 22 450

if (22>=20 AND FALSE


450>=500)
display Not qualified.

EXAMPLE 8: Student Discount – Under 18 OR student card → 15% off


Problem: Customer gets 15% discount if under 18 OR holds a student card.
IPO Chart:
INPUT PROCESSING OUTPUT
age (Integer) Enter age, card status, and price (Real)
studentCard (Boolean) price
price (Real) If age < 18 OR studentCard:
price = price * 0.85
Display final price

Pseudocode:
StudentDiscount
enter age, studentCard, price
if age < 18 OR studentCard then
price = price * 0.85
endif
display "Final price: R ", price
end

Trace Table:
Instruction age studentCard price Output
enter 25 TRUE 200

if (25<18 OR TRUE
TRUE)
calc 170

Sol Plaatje University | Page 27 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display R170

EXAMPLE 9: Commission – Sales < R3500: 8%, Sales >= R3500: 12.8%
Problem: Employee earns R1200 basic + commission. < R3500 sales = 8%, else = 12.8%. 5% goes to
manager.
IPO Chart:
INPUT PROCESSING OUTPUT
sales (Real) Enter sales netIncome (Real)
If sales < 3500: commission =
sales * 0.08
Else: commission = sales *
0.128
managerCut = commission *
0.05
netIncome = 1200 +
commission - managerCut

Pseudocode:
CalcIncome
enter sales
if sales < 3500 then
commission = sales * 0.08
else
commission = sales * 0.128
endif
managerCut = commission * 0.05
netIncome = 1200 + commission - managerCut
display "Net income: R ", netIncome
end

Trace Table:
Instruction sales commission managerCut netIncome Output
enter 4000

if FALSE
(4000<3500)
calc 512

calc 25.60

calc 1686.40

display R1686.40

EXAMPLE 10: A value between 17 and 47 – Swap A and B


Problem: If A > 17 AND A < 47: swap A and B. If A = 5 OR A = 87: A += 20, B -= 5.

Sol Plaatje University | Page 28 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

IPO Chart:
INPUT PROCESSING OUTPUT
A (Real) Enter A and B A (Real)
B (Real) If A > 17 AND A < 47: swap B (Real)
using temp variable
Else if A = 5 OR A = 87: A =
A+20, B = B-5

Pseudocode:
SwapOrAdjust
enter A, B
if A > 17 AND A < 47 then
temp = A
A = B
B = temp
else
if A = 5 OR A = 87 then
A = A + 20
B = B - 5
endif
endif
display "A = ", A, " B = ", B
end

Trace Table:
Instruction A B temp Output
enter 25 10

if (25>17 AND TRUE


25<47)
assign 25

assign 10

assign 25

display A=10 B=25

Sol Plaatje University | Page 29 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

CHAPTER 5: The Selection Control Structure – Part 2


📌 Chapter 5 introduces Nested IF statements (if inside if) and the SELECT CASE statement
for multiple-choice decisions. Nested IFs are used when more than one sequential decision
must be made before an action can be taken.

5.1 Nested IF Statements


A nested IF places an IF statement inside another IF statement's body or else-clause. Each inner IF
must be indented and have its own matching endif.
if condition1 then
if condition2 then
statement1
else
statement2
endif
else
if condition3 then
statement3
else
statement4
endif
endif

Nested IF Examples with IPO, Pseudocode & Trace Table (10)


EXAMPLE 1: Gender & Age Points – Males/Females get different points based on age
Problem: Male > 15 → 17 pts; Male <= 15 → 20 pts; Female < 18 → 18 pts; Female >= 18 → 21 pts.
IPO Chart:
INPUT PROCESSING OUTPUT
gender (Char) Enter gender and age points (Integer)
age (Integer) Nested IF on gender, then age
Assign points

Pseudocode:
AssignPoints
enter gender, age
if gender = "M" then
if age > 15 then
points = 17
else
points = 20
endif
else
if gender = "F" then
if age < 18 then
Sol Plaatje University | Page 30 of 57
NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

points = 18
else
points = 21
endif
else
display "Invalid gender"
endif
endif
display "Points: ", points
end

Trace Table:
Instruction gender age points Output
enter F 19

if (F=M) FALSE

if (F=F) TRUE

if (19<18) FALSE

assign 21

display 21

EXAMPLE 2: Salary Increase by Department – A:7.2%, B:6.8%, Others:6.3%


Problem: Dept A: 7.2%, Dept B: 6.8%, all others: 6.3%. Calculate new monthly salary.
IPO Chart:
INPUT PROCESSING OUTPUT
deptCode (Char) Enter deptCode and salary monSalary (Real)
anSalary (Real) Validate salary is numeric
Convert to monthly, apply
increase per dept

Pseudocode:
CalcNewSalary
enter deptCode, anSalary
if anSalary is numeric then
monSalary = anSalary / 12
if deptCode = "A" then
monSalary = monSalary * 1.072
else
if deptCode = "B" then
monSalary = monSalary * 1.068
else
monSalary = monSalary * 1.063
endif
endif

Sol Plaatje University | Page 31 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display "New monthly salary: R ", monSalary


else
display "Salary must be numeric"
endif
end

Trace Table:
Instruction deptCode anSalary monSalary Output
enter A 24000

if numeric TRUE

calc 2000

if (A=A) TRUE

calc 2144

display R2144

EXAMPLE 3: A=5.2 and B – Nested conditions on variable values


Problem: If A=5.2 and B>20: A=A+5; if A=5.2 and B<=20: B=B-3.5; if A=6: A=0, B=0.
IPO Chart:
INPUT PROCESSING OUTPUT
A (Real) Enter A and B A (Real)
B (Real) Nested IF to test conditions and B (Real)
modify values

Pseudocode:
ModifyValues
enter A, B
if A = 5.2 then
if B > 20 then
A = A + 5
else
B = B - 3.5
endif
else
if A = 6 then
A = 0
B = 0
endif
endif
display "A = ", A, " B = ", B
end

Trace Table:

Sol Plaatje University | Page 32 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Instruction A B Output
enter 5.2 25

if (A=5.2) TRUE

if (25>20) TRUE

calc 10.2

display A=10.2 B=25

EXAMPLE 4: Shop Discount – 10+ items get discount, nested validation


Problem: Cheap Store: Enter selling price, number of items, discount %. Discount only if >= 10 items.
IPO Chart:
INPUT PROCESSING OUTPUT
price (Real) Enter all values discount (Real)
numItems (Integer) subtotal = price * numItems amountDue (Real)
discPct (Real) If numItems >= 10: discount =
subtotal * discPct/100
amountDue = subtotal -
discount

Pseudocode:
CheapStoreCalc
enter price, numItems, discPct
if price is numeric AND numItems is numeric then
subtotal = price * numItems
if numItems >= 10 then
discount = subtotal * discPct / 100
amountDue = subtotal - discount
display "Discount: R", discount
else
amountDue = subtotal
display "No discount applied"
endif
display "Amount due: R", amountDue
else
display "Invalid input"
endif
end

Trace Table:
Instruction numItems subtotal discount amountDue Output
enter 12

calc 360

if (12>=10) TRUE

Sol Plaatje University | Page 33 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

calc 36

calc 324

display R324

EXAMPLE 5: Employee Commission – Nested salary + commission tiers


Problem: R1200 basic + commission. Sales<R3500: 8%, else 12.8%. If department=7, extra R50
bonus.
IPO Chart:
INPUT PROCESSING OUTPUT
sales (Real) Enter sales and dept netIncome (Real)
dept (Integer) Calculate commission using
nested IF
If dept=7: add R50 bonus
Display net income

Pseudocode:
NetIncome
enter sales, dept
if sales < 3500 then
commission = sales * 0.08
else
commission = sales * 0.128
endif
if dept = 7 then
bonus = 50
else
bonus = 0
endif
net = 1200 + commission + bonus - commission * 0.05
display "Net income: R ", net
end

Trace Table:
Instruction sales dept commission bonus net Output
enter 4000 7

if FALSE
(<3500)
calc 512

if TRUE
(dept=7)
assign 50

calc 1736.40

Sol Plaatje University | Page 34 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display R1736.40

EXAMPLE 6: Student Grade – Nested ranges for A, B, C, D, F


Problem: Mark >= 75: A; 60-74: B; 50-59: C; 40-49: D; < 40: F. Display grade.
IPO Chart:
INPUT PROCESSING OUTPUT
mark (Integer) Enter mark grade (Char)
Nested IFs to determine grade

Pseudocode:
AssignGrade
enter mark
if mark >= 75 then
grade = "A"
else
if mark >= 60 then
grade = "B"
else
if mark >= 50 then
grade = "C"
else
if mark >= 40 then
grade = "D"
else
grade = "F"
endif
endif
endif
endif
display "Grade: ", grade
end

Trace Table:
Instruction mark grade Output
enter 65

if (>=75) FALSE

if (>=60) TRUE

assign B

display Grade: B

EXAMPLE 7: Three Numbers – Find the largest using nested IF


Problem: Enter three numbers A, B, C. Use nested IF to find and display the largest.

Sol Plaatje University | Page 35 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

IPO Chart:
INPUT PROCESSING OUTPUT
A (Real) Enter A, B, C largest (Real)
B (Real) Nested IF to compare and find
C (Real) largest

Pseudocode:
FindLargest
enter A, B, C
if A > B then
if A > C then
largest = A
else
largest = C
endif
else
if B > C then
largest = B
else
largest = C
endif
endif
display "Largest: ", largest
end

Trace Table:
Instruction A B C largest Output
enter 5 12 9

if (5>12) FALSE

if (12>9) TRUE

assign 12

display 12

EXAMPLE 8: Rental Car Cost – Days and type nested


Problem: Car type A: R250/day. Car type B: R180/day. If days > 7 get 10% discount.
IPO Chart:
INPUT PROCESSING OUTPUT
carType (Char) Enter type and days totalCost (Real)
days (Integer) Nested IF to set rate, then
check for discount

Pseudocode:

Sol Plaatje University | Page 36 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

RentalCost
enter carType, days
if carType = "A" then
rate = 250
else
rate = 180
endif
cost = rate * days
if days > 7 then
cost = cost * 0.90
endif
display "Total cost: R ", cost
end

Trace Table:
Instruction carType days cost Output
enter A 10

if (A=A) TRUE

calc 2500

if (10>7) TRUE

calc 2250

display R2250

EXAMPLE 9: Tebogo Full Budget – Validation with nested IPO


Problem: Full Tebogo problem with salary validation: must be > 0 AND < 1800.
IPO Chart:
INPUT PROCESSING OUTPUT
salary (Real) Enter salary food
If salary > 0 AND salary < 1800: clothes
remainder = salary - 450 transport
Calculate 5 categories charity
Else: display error pocket

Pseudocode:
TebogoBudgetFull
display "Enter monthly salary (must be less than R1800):"
enter salary
if salary > 0 AND salary < 1800 then
remainder = salary - 450
if remainder > 0 then
food = remainder * 0.50
clothes = remainder * 0.20
transport = remainder * 0.15

Sol Plaatje University | Page 37 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

charity = remainder * 0.05


pocket = remainder - food - clothes - transport - charity
display "Rent: R450"
display "Food: R", food
display "Clothes: R", clothes
display "Transport: R", transport
display "Charity: R", charity
display "Pocket: R", pocket
else
display "Salary too low to cover rent"
endif
else
display "Invalid salary. Must be between R1 and R1799"
endif
end

Trace Table:
Step salary remainder food pocket Output
enter 1600

if (>0 AND TRUE


<1800)
calc 1150

if (>0) TRUE

calc 575

calc 115

display Food:R575
Pocket:R115

EXAMPLE 10: Select Case: Day Name – Map number 1-7 to day name
Problem: Enter a number 1-7. Display the corresponding day of the week using SELECT CASE.
IPO Chart:
INPUT PROCESSING OUTPUT
dayNum (Integer) Enter dayNum dayName (String)
Select case dayNum to assign
dayName

Pseudocode:
DayName
display "Enter day number (1-7):"
enter dayNum
select case dayNum
case 1: dayName = "Monday"
case 2: dayName = "Tuesday"

Sol Plaatje University | Page 38 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

case 3: dayName = "Wednesday"


case 4: dayName = "Thursday"
case 5: dayName = "Friday"
case 6: dayName = "Saturday"
case 7: dayName = "Sunday"
case else: dayName = "Invalid"
end select
display "Day: ", dayName
end

Trace Table:
Instruction dayNum dayName Output
enter 5

case 5 Friday

display Friday

Sol Plaatje University | Page 39 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

CHAPTER 6: Iteration Using a Fixed Count Loop (FOR-


NEXT)
📌 The FOR-NEXT loop is used when the EXACT number of repetitions is known. Key
concepts: • Index variable counts iterations • Begin-value, end-value, optional step •
Accumulator: variable that sums values inside a loop • Counter: accumulator that adds 1 each
iteration

Syntax:
for variable = begin-value to end-value [step value]
statement(s)
next variable

FOR-NEXT Loop Examples with IPO, Pseudocode & Trace Table (10)
EXAMPLE 1: Display 1 to 10 – Basic for-next loop
Problem: Display consecutive numbers from 1 to 10 on one line.
IPO Chart:
INPUT PROCESSING OUTPUT
(no input) for i = 1 to 10: display i i (Integer) displayed

Pseudocode:
Display1To10
for i = 1 to 10
display i, " "
next i
end

Trace Table:
i Output
1 1
2 2
3 3
... ...
10 10

EXAMPLE 2: Display 10 to 1 – Descending with step -1


Problem: Display consecutive numbers from 10 to 1 in descending order.
IPO Chart:
INPUT PROCESSING OUTPUT

Sol Plaatje University | Page 40 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

(no input) for i = 10 to 1 step -1: display i Output: 10 9 8 ... 1

Pseudocode:
Descend10To1
for i = 10 to 1 step -1
display i, " "
next i
end

Trace Table:
i Output
10 10
9 9
8 8
... ...
1 1

EXAMPLE 3: Sum of First 5 Odd Numbers – Accumulator


Problem: Calculate and display the sum of the first five odd numbers (1+3+5+7+9=25).
IPO Chart:
INPUT PROCESSING OUTPUT
(no input) sum=0, odd=1 sum (Integer)
for k=1 to 5: sum=sum+odd,
odd=odd+2
Display sum

Pseudocode:
SumOddNumbers
sum = 0
odd = 1
for k = 1 to 5
sum = sum + odd
odd = odd + 2
next k
display "Sum of first 5 odds: ", sum
end

Trace Table:
k odd sum Output
1 1 1

2 3 4

Sol Plaatje University | Page 41 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

3 5 9

4 7 16

5 9 25

done Sum=25

EXAMPLE 4: Average of 8 Numbers – Input validation in loop


Problem: Enter 8 integers between 5 and 48. Calculate and display the average.
IPO Chart:
INPUT PROCESSING OUTPUT
number (Integer) × 8 sum=0, for x=1 to 8 average (Real)
Enter number, validate 5<n<48
sum = sum + number
average = sum / 8

Pseudocode:
AverageOf8
sum = 0
for x = 1 to 8
display "Enter integer between 5 and 48:"
enter number
if number > 5 AND number < 48 then
sum = sum + number
else
display "Invalid - re-enter"
x = x - 1
endif
next x
average = sum / 8
display "Average: ", average
end

Trace Table:
x number sum Output
1 20 20

2 35 55

... ... ...

8 40 240

— — — Average: 30

EXAMPLE 5: Display Even Numbers – Enter start and count

Sol Plaatje University | Page 42 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Problem: Enter starting even number and how many even numbers to display. Display them.
IPO Chart:
INPUT PROCESSING OUTPUT
beginNo (Integer) Validate inputs evenNo (Integer)
howMany (Integer) Check beginNo is even (mod 2
= 0)
for x=1 to howMany: display
even, even+=2

Pseudocode:
DisplayEvens
enter beginNo, howMany
if beginNo is numeric AND howMany > 0 then
remainder = beginNo MOD 2
if remainder = 0 then
even = beginNo
for x = 1 to howMany
display even, " "
even = even + 2
next x
else
display "Start must be an even number"
endif
else
display "Invalid input"
endif
end

Trace Table:
x even Output
1 8 8
2 10 10
3 12 12
... ... ...
10 26 26

EXAMPLE 6: Highest & Lowest Test Mark – 10 students


Problem: Enter name and mark for 10 students. Find and display the student with highest and lowest
marks.
IPO Chart:
INPUT PROCESSING OUTPUT
stName (String) × 10 Enter first student, set highestName
testMark (Integer) × 10 highest=lowest=first mark highest

Sol Plaatje University | Page 43 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

for st=2 to 10: compare marks lowestName


Display highest and lowest lowest
names and marks

Pseudocode:
TestResults
display "Enter name of first student:"
enter stName
display "Enter test mark:"
enter testMark
highestName = stName
highest = testMark
lowestName = stName
lowest = testMark
for st = 2 to 10
enter stName, testMark
if testMark > highest then
highest = testMark
highestName = stName
else
if testMark < lowest then
lowest = testMark
lowestName = stName
endif
endif
next st
display "Highest: ", highestName, " - ", highest
display "Lowest: ", lowestName, " - ", lowest
end

Trace Table:
st stName mark highest lowest Output
1 Danny 50 50 50

2 Bill 67 67 50

3 Don 92 92 50

4 Dave 28 92 28

... ... ... ... ...

done Don:92
Dave:28

EXAMPLE 7: Multiplication Table – Display 5 times table


Problem: Display the multiplication table for the number 5, from 1 to 10.
IPO Chart:
INPUT PROCESSING OUTPUT

Sol Plaatje University | Page 44 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

tableNum (Integer)=5 for i=1 to 10: display tableNum * result (Integer)


i

Pseudocode:
TimesTable
tableNum = 5
for i = 1 to 10
result = tableNum * i
display tableNum, " x ", i, " = ", result
next i
end

Trace Table:
i result Output
1 5 5 x 1 = 5
2 10 5 x 2 = 10
3 15 5 x 3 = 15
... ... ...
10 50 5 x 10 = 50

EXAMPLE 8: Division by Subtraction – Divide totNumber by 5


Problem: Enter integer > 400. Divide by 5 using a for-next loop (by subtracting), discard remainder.
IPO Chart:
INPUT PROCESSING OUTPUT
totNumber (Integer) Validate totNumber > 400 result (Integer)
result = 0, remainder =
totNumber
for k=1 to totNumber step 5:
result++
Display result

Pseudocode:
DivisionBySubtract
enter totNumber
if totNumber > 400 AND totNumber is numeric then
remainder = totNumber
result = 0
do while remainder >= 5
remainder = remainder - 5
result = result + 1
loop
display "Result of ", totNumber, " / 5 = ", result
else

Sol Plaatje University | Page 45 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display "Invalid input"


endif
end

Trace Table:
Step totNumber remainder result Output
enter 425

init 425 0

loop 1 420 1

loop 2 415 2

... ... ...

loop 85 0 85

display 425/5=85

EXAMPLE 9: Even Numbers Sum – for loop with step 2


Problem: Calculate the sum of even numbers from 2 to 20 using a for-next loop with step 2.
IPO Chart:
INPUT PROCESSING OUTPUT
(no input) sum=0 sum (Integer)
for i=2 to 20 step 2: sum=sum+i
Display sum

Pseudocode:
SumEvens
sum = 0
for i = 2 to 20 step 2
sum = sum + i
next i
display "Sum of even numbers 2-20: ", sum
end

Trace Table:
i sum Output
2 2

4 6

6 12

... ...

20 110

Sol Plaatje University | Page 46 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

— — Sum=110

EXAMPLE 10: Count Integers into Sum – Consecutive integers from 24 [Sem Test 2.2]
Problem: Calculate sum of consecutive integers starting at 24 while sum < 23456. Display how many
integers were added.
IPO Chart:
INPUT PROCESSING OUTPUT
(no input – uses sentinel logic) sum=0, number=24, count=0 count (Integer)
do while sum < 23456:
sum += number, number++,
count++
Display count

Pseudocode:
CalcSum
sum = 0
number = 24
count = 0
do while sum < 23456
sum = sum + number
number = number + 1
count = count + 1
loop
display "Number of integers added: ", count
end

Trace Table:
count number sum Output
0 24 0

1 25 24

2 26 49

3 27 75

... ... ...

done >=23456 Count displayed

Sol Plaatje University | Page 47 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

CHAPTER 7: Iteration Using the DO Loop


📌 The DO loop is used when the number of repetitions is NOT known in advance. • DO-
WHILE (pre-test): tests condition BEFORE body – body may never execute • DO-LOOP-
UNTIL (post-test): tests condition AFTER body – body executes AT LEAST ONCE • A
SENTINEL is a special value used to signal the end of input (e.g. -1 for no more data)

7.1 Pre-Test Loop: DO-WHILE


do while condition
statement(s)
loop

7.2 Post-Test Loop: DO-LOOP-UNTIL


do
statement(s)
loop until condition

DO Loop Examples with IPO, Pseudocode & Trace Table (10)


EXAMPLE 1: Fishing Competition – Best fisherman using sentinel -1
Problem: Enter fisherman names and fish counts. Use -1 as sentinel. Display the winner.
IPO Chart:
INPUT PROCESSING OUTPUT
fmName (String) winnerNumber=0, enter first winner (String)
noFish (Integer) noFish winnerNumber (Integer)
do while noFish <> -1:
enter fmName
if noFish > winnerNumber:
update winner
enter next noFish
Display winner and count

Pseudocode:
FishingWinner
winnerNumber = 0
display "Fish count (-1 to stop):"
enter noFish
do while noFish <> -1
enter fmName
if noFish > winnerNumber then
winnerNumber = noFish
winner = fmName
endif

Sol Plaatje University | Page 48 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

display "Next fish count (-1 to stop):"


enter noFish
loop
display "Winner: ", winner, " with ", winnerNumber, " fish"
end

Trace Table:
noFish fmName winnerNumber winner Output
8 Sam 8 Sam

2 Johnny 8 Sam

7 Kevin 8 Sam

10 Fred 10 Fred

12 Ted 12 Ted

9 Paul 12 Ted

-1 (end) Ted: 12 fish

EXAMPLE 2: Alexis Shopping – Accumulate prices until sentinel 0


Problem: Enter item prices (0 to stop). Calculate total. If > R100 apply 3.5% discount. Compare to
purse money.
IPO Chart:
INPUT PROCESSING OUTPUT
price (Real) Enter purseMoney and first change (Real) or shortMoney
purseMoney (Real) price (Real)
do while price <> 0: total +=
price, enter next
If total > 100: apply 3.5%
discount
If purseMoney >= total: change
= purseMoney - total
Else: shortMoney = total -
purseMoney

Pseudocode:
AlexisShopping
total = 0
display "Money in purse: "
enter purseMoney
display "Enter price (0 to stop):"
enter price
do while price <> 0
total = total + price
display "Next price (0 to stop):"
enter price

Sol Plaatje University | Page 49 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

loop
if total > 100 then
total = total - total * 0.035
endif
if purseMoney >= total then
change = purseMoney - total
display "Change: R ", change
else
shortMoney = total - purseMoney
display "Need R ", shortMoney, " more"
endif
end

Trace Table:
price total Discount? purseMoney Output
45 45 150

30 75

35 110

0 stop YES: 106.15

compare 150>106.15 Change: R43.85

EXAMPLE 3: Ticket Sales – Loop until all 100 tickets sold


Problem: 100 tickets available. Keep selling until noTickets = 0. Post-test loop.
IPO Chart:
INPUT PROCESSING OUTPUT
ticketsToBuy (Integer) noTickets = 100 noTickets (Integer)
do: message (String)
enter ticketsToBuy
if enough: noTickets -=
ticketsToBuy
else: show available
loop until noTickets = 0

Pseudocode:
TicketSales
noTickets = 100
do
display "Tickets to buy?"
enter ticketsToBuy
if ticketsToBuy <= noTickets then
noTickets = noTickets - ticketsToBuy
display "Sold. Remaining: ", noTickets
else
display "Only ", noTickets, " available"

Sol Plaatje University | Page 50 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

endif
loop until noTickets = 0
display "All tickets sold!"
end

Trace Table:
ticketsToBuy noTickets Output
30 70 Sold. Remaining:70
40 30 Sold. Remaining:30
30 0 Sold. Remaining:0
stop 0 All tickets sold!

EXAMPLE 4: Sum of Consecutive Integers from 24 – Pre-test loop [Sem Test 2.2]
Problem: Calculate sum of consecutive integers starting at 24 while sum < 23456. Display count.
IPO Chart:
INPUT PROCESSING OUTPUT
(no user input) sum=0, number=24, count=0 count (Integer)
do while sum < 23456:
sum+=number, number++,
count++
Display count

Pseudocode:
CalcSum
sum = 0
number = 24
count = 0
do while sum < 23456
sum = sum + number
number = number + 1
count = count + 1
loop
display "Integers added: ", count
end

Trace Table:
Loop number sum count Output
1 24 24 1

2 25 49 2

3 26 75 3

... ... ... ...

Sol Plaatje University | Page 51 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

done >=23456 final count


displayed

EXAMPLE 5: Sales Input Validation – Repeat until valid numeric input


Problem: Prompt user to enter a sales amount. Keep repeating until a valid numeric value >= 0 is
entered.
IPO Chart:
INPUT PROCESSING OUTPUT
salesAmount (Real) do: enter salesAmount salesAmount (Real)
loop until salesAmount is
numeric AND salesAmount >= 0
Process valid input

Pseudocode:
ValidSalesInput
do
display "Enter sales amount (must be >= 0):"
enter salesAmount
if NOT (salesAmount is numeric AND salesAmount >= 0) then
display "Invalid. Please re-enter."
endif
loop until salesAmount is numeric AND salesAmount >= 0
display "Valid amount entered: R ", salesAmount
end

Trace Table:
Attempt salesAmount Valid? Output
1 abc FALSE Invalid. Re-enter.
2 -5 FALSE Invalid. Re-enter.
3 150 TRUE Valid: R150

EXAMPLE 6: Highest Sales Amount – Use sentinel -1 to stop


Problem: Enter sales amounts until -1 is entered. Display the highest sales amount.
IPO Chart:
INPUT PROCESSING OUTPUT
salesAmount (Real) highestSales = 0 highestSales (Real)
Enter first salesAmount
do while salesAmount <> -1:
if salesAmount > highest:
update
Enter next salesAmount
Display highest

Sol Plaatje University | Page 52 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Pseudocode:
HighestSales
highestSales = 0
display "Enter sales amount (-1 to stop):"
enter salesAmount
do while salesAmount <> -1
if salesAmount > highestSales then
highestSales = salesAmount
endif
display "Next amount (-1 to stop):"
enter salesAmount
loop
display "Highest sales: R ", highestSales
end

Trace Table:
salesAmount highestSales Output
500 500

1200 1200

800 1200

350 1200

-1 stop Highest: R1200

EXAMPLE 7: Name and Age Entry – Repeat for multiple people until stop
Problem: Enter name and age for people. Use 'STOP' as sentinel for name. Display count entered.
IPO Chart:
INPUT PROCESSING OUTPUT
name (String) count=0 count (Integer)
age (Integer) Enter first name
do while name <> 'STOP':
enter age, count++
display name and age
enter next name
Display count

Pseudocode:
PeopleEntry
count = 0
display "Enter name (STOP to quit):"
enter name
do while name <> "STOP"
display "Enter age:"

Sol Plaatje University | Page 53 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

enter age
count = count + 1
display count, ": ", name, " - ", age
display "Enter next name (STOP to quit):"
enter name
loop
display "Total people entered: ", count
end

Trace Table:
name age count Output
Alice 25 1 1: Alice - 25
Bob 30 2 2: Bob - 30
STOP — 2 Total: 2

EXAMPLE 8: Repeat Until Positive – Post-test loop validation


Problem: Enter a number. Keep asking until user enters a positive number (> 0).
IPO Chart:
INPUT PROCESSING OUTPUT
number (Integer) do: number (Integer)
display prompt
enter number
loop until number > 0
Display the valid number

Pseudocode:
PositiveNumber
do
display "Enter a positive number:"
enter number
if number <= 0 then
display "Must be positive. Try again."
endif
loop until number > 0
display "You entered: ", number
end

Trace Table:
Attempt number Valid? Output
1 0 FALSE Must be positive.
2 -3 FALSE Must be positive.
3 7 TRUE You entered: 7

Sol Plaatje University | Page 54 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

EXAMPLE 9: ATM Withdrawal – Check balance before dispensing


Problem: Enter withdrawal amount. Loop while amount > balance. Display updated balance.
IPO Chart:
INPUT PROCESSING OUTPUT
amount (Real) Enter balance balance (Real)
balance (Real) do while amount > balance OR
amount <= 0:
display error, re-enter
balance = balance - amount
Display new balance

Pseudocode:
ATMWithdrawal
display "Account balance: "
enter balance
display "Amount to withdraw:"
enter amount
do while amount > balance OR amount <= 0
display "Invalid amount. Enter between R1 and R", balance
enter amount
loop
balance = balance - amount
display "New balance: R ", balance
end

Trace Table:
amount balance Valid? Output
0 1000 FALSE Invalid amount
1200 1000 FALSE Invalid amount
500 1000 TRUE

— 500 New balance: R500

EXAMPLE 10: Monthly Salary Categories – Full Tebogo problem with do-loop
Problem: Full budget program for Tebogo. Use a do-loop to keep prompting until salary is valid (<
R1800 and > 0).
IPO Chart:
INPUT PROCESSING OUTPUT
salary (Real) do: food
enter salary clothes
loop until salary > 0 AND salary transport
< 1800 charity
remainder = salary - 450 pocket

Sol Plaatje University | Page 55 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

Calculate and display 5


categories

Pseudocode:
TebogoBudgetLoop
do
display "Enter monthly salary (must be > 0 and < R1800):"
enter salary
if NOT (salary > 0 AND salary < 1800) then
display "Invalid salary. Please re-enter."
endif
loop until salary > 0 AND salary < 1800
remainder = salary - 450
food = remainder * 0.50
clothes = remainder * 0.20
transport = remainder * 0.15
charity = remainder * 0.05
pocket = remainder * 0.10
display "Rent: R450"
display "Food: R", food
display "Clothes: R", clothes
display "Transport: R", transport
display "Charity: R", charity
display "Pocket money: R", pocket
end

Trace Table:
Attempt salary Valid? food pocket Output
1 2000 FALSE Invalid.
Re-enter.
2 1500 TRUE

— — — 525 105 Food:R525


Pocket:R105

Sol Plaatje University | Page 56 of 57


NADF 511 – Applications Development Foundations | Chapters 4–7 Study Guide

QUICK REFERENCE: Key Concepts Summary


Problem-Solving Steps
• 1. Read and understand the problem
• 2. Identify INPUT variables
• 3. Identify OUTPUT variables
• 4. Identify PROCESSING (calculations, decisions, loops)
• 5. Draw the IPO chart
• 6. Write the pseudocode
• 7. Create test data (trace table)
• 8. Verify output is correct

IPO Chart Template


INPUT PROCESSING OUTPUT
List all input variables with types List all processing steps in order List all output variables with
types

Pseudocode Keywords
Keyword Purpose
display Show output to screen
enter Read input from user
if / endif Simple conditional
if / else / endif Two-way conditional
for / next Fixed count loop
do while / loop Pre-test (unknown count) loop
do / loop until Post-test loop (runs at least once)
mod Returns remainder of division (17 mod 6 = 5)
\ Integer division (17 \ 6 = 2)
AND / OR / NOT Logical operators
is numeric Data validation test

Sol Plaatje University | Page 57 of 57

You might also like