Week 3.1
Week 3.1
Example:
Prepare test data to test all possible conditions for a program that
contains decision structures.
Write algorithms containing Simple if statements, If-then-else
statements, Compound if statements and Boolean variables.
Code defensively and do data validation where-ever possible.
if statement
CalcCakePrice
~ Calculate the selling price of cake
display “Please enter the cost of the cake”
enter expense
~ Add profit and calculate price per slice
cakePrice= expense + expense * 0.3 ~ Intermediate variable cakePrice
slicePriceInteger = cakePrice \ 10
slicePriceDecimal = cakePrice / 10
Algorithm
ReadingSpeed
display “Provide number of pages per book ”
enter bookPages
display “Provide number of pages Dennis can read per day ”
enter dayPages
~ Calculate days per book
bookDays = bookPages / dayPages
~ Determine days to read 5 books
days = bookDays * 5 ~ An intermediate variable is used
Algorithm for if then else statement
The Bright Light Company is increasing the salaries of its employees according to which department
they work in, as shown in Table 7
A 7.2
B 6.8