You are Here: Home

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

Announcements
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)

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:
Updated: October 4, 2016
Today on TSR

Fastest and slowest uni offer senders

When will you get your offer?

Apocalypse sky is here

Discussions on TSR

• Latest
• 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
Useful resources

Can you help? Study Help unanswered threadsStudy Help rules and posting guidelines

Groups associated with this forum:

View associated groups
Discussions on TSR

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

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