HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /This is the kind of long scenario question that ends Paper 2…
HardComputer ScienceHigh School (9–10)Computer Science › Algorithms and Problem-SolvingcodingConceptualIGCSE

This is the kind of long scenario question that ends Paper 2…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

This is the kind of long scenario question that ends Paper 2. Answer in pseudocode.

A cinema ticket machine sells tickets to a group, one person at a time. For each person the machine asks for an age, until −1-1−1 is input. The rules are:

  • an age must be a whole number from 000 to 120120120; any other value gets an error message and is not charged;
  • a child (under 121212) pays 555 dollars, an adult (121212 to 646464) pays 999 dollars and a senior (656565 or over) pays 666 dollars;
  • at the end, the machine outputs the number of tickets and the total to pay.

Write the algorithm, with a prompt before each input and comments. Then give the two final outputs for the inputs 343434, 888, 707070, 130130130, 151515, −1-1−1.

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Cambridge pseudocode: keywords in capitals, names in mixed case, ← for assignment, INPUT and OUTPUT, IF ... THEN ... ELSE ... ENDIF, CASE OF ... OTHERWISE ... ENDCASE, FOR ... TO ... STEP ... NEXT, WHILE ... DO ... ENDWHILE, REPEAT ... UNTIL. DIV(a, b) is the whole-number quotient and MOD(a, b) the remainder.

The worked solution

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. Two running values (Tickets and Total), a pre-condition loop that stops on −1-1−1, a validity check, then the price.

A model answer.

pseudocode
// Ticket machine for a group
Total ← 0
Tickets ← 0
OUTPUT "Enter an age, or -1 to finish"
INPUT Age
WHILE Age <> -1 DO
    IF Age < 0 OR Age > 120
      THEN
        OUTPUT "Age must be 0 to 120"
      ELSE
        IF Age < 12
          THEN
            Price ← 5          // child
          ELSE
            IF Age < 65
              THEN
                Price ← 9      // adult
              ELSE
                Price ← 6      // senior
            ENDIF
        ENDIF
        Total ← Total + Price
        Tickets ← Tickets + 1
    ENDIF
    OUTPUT "Enter an age, or -1 to finish"
    INPUT Age
ENDWHILE
OUTPUT "Tickets: ", Tickets
OUTPUT "Total: ", Total

The run. 343434 is an adult: 999. 888 is a child: 555. 707070 is a senior: 666. 130130130 is out of range, so it gets the error and no ticket. 151515 is an adult: 999. Then −1-1−1 ends the loop. Tickets: 444. Total: 9+5+6+9=299 + 5 + 6 + 9 = 299+5+6+9=29 dollars.

A marking list. One mark for each point.

  1. Total starts at 000.
  2. Tickets starts at 000.
  3. A prompt before each input.
  4. An input before the loop and one at the end of the loop body.
  5. The loop stops when −1-1−1 is input.
  6. Ages below 000 or above 120120120 are rejected.
  7. An error message for a rejected age.
  8. A rejected age is not counted or charged.
  9. Under 121212 pays 555.
  10. 121212 to 646464 pays 999 (the boundaries 121212 and 646464 are right).
  11. 656565 or over pays 666.
  12. The price is added to Total.
  13. Tickets goes up by 111 for each valid age.
  14. Both results are output after the loop, with messages.
  15. Meaningful names and comments.

Answer: Tickets: 4 and Total: 29.

Check. Good test data here includes the boundaries 111111 and 121212, 646464 and 656565, and 000 and 120120120 with their rejected neighbours −2-2−2 and 121121121. Note that −1-1−1 cannot be used as test data for the range check, because it is the stop value.

Log in to save this for later
← All Problems
← This algorithm outputs the even numbers from 2 to 12…Dry-run this algorithm and complete a trace table with the columns A, B and OUTPUT… →
More onComputer Science › Algorithms and Problem-Solving

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Writing pseudocodePseudocode, Trace Tables and Testing

More on this topic

  1. A delivery company adds a check digit to each parcel number…Medium
  2. Name the check in each case. Say whether it is validation or verification…Easy
  3. A bubble sort is changed so that it sorts in descending order: the comparison becomes IF…Hard
  4. A shop stores the colours of the ten bicycles in its window in an array Colours: red, blue, red…
Medium
  • A bubble sort puts the scores 5, 1, 4, 2, 8 into ascending order…Medium
  • All problems on this topic →