Hey! Sign in to get help with your study questionsNew here? Join for free to post

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

Announcements Posted on
TSR's new app is coming! Sign up here to try it first >> 17-10-2016
    • 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)
Write a reply…


Submit reply


Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. Oops, you need to agree to our Ts&Cs to register
  2. Slide to join now Processing…

Updated: October 4, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Do you like sleeping in a cold room?

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

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