Hey there! Sign in to join this conversationNew here? Join for free

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

Announcements
    • Thread Starter
    Offline

    12
    ReputationRep:
    A computer program contains the following instructions:

    INPUT X
    INPUT Y
    Z = -1
    REPEAT
    Z = Z + 1
    Y = Y - X
    UNTIL Y < 0
    OUTPUT Z

    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?
    Offline

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

    Code:
    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)
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Break up or unrequited love?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • 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.