Join TSR now and get all your revision questions answeredSign up now

Would this type of error would this be? (C)

    • Thread Starter

    A computer program contains the following instructions:

    Z = -1
    Z = Z + 1
    Y = Y - X
    UNTIL Y < 0

    The program is given the inputs: -4, 12
    Explain why this will produce an error and what type of error it will produce [3]

    I think this is a logical error because when 12 - -4, the value of Y will get bigger and bigger therefore Z would never get printed.

    Is my answer right?

    It would be a runtime error. Here is an example in JavaScript:

    aFunction = function(x, y){
        var z = 1;
        while (y >= 0) {
            z = z + 1;
            y = y - x;
            return z;
    If you pass in x as -4 and y as 12, y will always be greater than 0 so it will loop forever and never reach the return statement.

    It is a runtime error because this would occur when the code is run. There is no logic in the code that would cause it to loop infinitely because it depends on what the input is, a logic error would have been if you wanted to multiply the numbers after you subtracted them for example 2 * y - x will multiply y by 2 then take away x where the correct way would be 2 * (y - x)
Which party will you be voting for in the General Election 2017?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.