Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The ticket price rules are: under 5 free, under 13 pays 50, under 60 pays 100, and the rest pay 70. Write the test table with the values at the edges and the price that each one must give. Then write the program, and check that it passes every row.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. The edges are 5, 13 and 60. Test the value just below, at, and just above each edge, and one value inside each group, and the extremes.
| Age | Expected price | Why |
|---|---|---|
| 0 | 0 | the smallest age, free |
| 4 | 0 | just below the first edge |
| 5 | 50 | at the edge: 5 is not under 5 |
| 12 | 50 | just below the second edge |
| 13 | 100 | at the edge |
| 59 | 100 | just below the third edge |
| 60 | 70 | at the edge |
| 90 | 70 | a very old age |
The program.
Check. The output matches the column "Expected price" for each row.
Answer: The table above. If the program used age <= 5, the row for 5 would show 0 and fail, which is the reason for the test.
Log in to join the discussion.
Loading…