Skip to content
ExamSpine

Lesson 6.1 · Answer it

Bill share errors

6 marksYou mark it yourself against the marking points

This program reads a bill in whole dollars, then the number of people sharing it, and prints each person's share, rounded down. In Java it runs inside a main method, with Scanner imported.

bill = int(input())
people = int(input())
share = bill // people
print("Each pays " + str(share))
Scanner in = new Scanner(System.in);
int bill =
    Integer.parseInt(in.nextLine());
int people =
    Integer.parseInt(in.nextLine());
int share = bill / people;
System.out.println(
    "Each pays " + share);

(a) The user types 60 and then 0. State the kind of error, and state how far the program gets before it stops. [2]

(b) Someone changes the division into a multiplication by mistake. With 60 and 4, the program prints Each pays 240. State the kind of error, and explain how you would notice it. [2]

(c) Someone deletes the last closing round bracket in the program. State the kind of error, and state what happens when the program is started. [2]

[6]