You are Here: Home

# 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
1. 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.

2. 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)

## Register

Thanks for posting! You just need to create an account in order to submit the post
1. this can't be left blank
2. this can't be left blank
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
1. Oops, you need to agree to our Ts&Cs to register

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.

This forum is supported by:
Today on TSR

### How does exam reform affect you?

From GCSE to A level, it's all changing

Poll
Useful resources