Course Content
Paper 2 – Problem Solving Approach -Practical
0/102
Past Paper-2 May/June 2025
Past Paper-1 May/June 2025
Download Files
0/1
Olevel : Computer Science 2210 / IGCSE 0478 : Recorded

In today’s lesson, we are going to learn about one of the most important types of validation used in computer programs: the Range Check. A range check is used to make sure that a number entered by the user falls within a specific and acceptable limit. This helps prevent unrealistic, impossible, or invalid numbers from being stored or processed by the computer. Range checks are commonly used in marks entry systems, age verification, salary limits, temperature inputs, and many more real-world applications.

Let’s understand this concept through a very clear and simple example: checking whether a student’s marks lie between 0 and 40. Imagine a teacher entering marks for a test where the maximum possible score is 40. If the teacher accidentally enters something impossible, like –5 or 75, the system should not accept it. This is exactly why we use a range check—to ensure only values within the correct range are accepted.

Now let’s look at the pseudocode step by step. We begin with the line:
DECLARE MARKS : INTEGER
This simply tells the computer that we will be receiving an integer value in the variable called MARKS. Next, the program displays a message using:
OUTPUT “Enter marks:”
This is a prompt for the user to enter a number. Then we collect the user input with:
INPUT MARKS
At this point, the computer now holds whatever number the user entered—but we still don’t know if it is valid or not.

This is where the range check begins. We write a WHILE loop, which continues repeating as long as the entered marks are OUTSIDE the valid range. The condition is:
WHILE MARKS < 0 OR MARKS > 40
This means:

  • If the marks are LESS than 0

  • OR if the marks are GREATER than 40
    The loop will continue, and the user will be asked to re-enter the marks. Inside the loop, we have:
    OUTPUT “Re-enter marks between 0 to 40”
    This message tells the user exactly what went wrong and what they need to do. Then the program takes input again with another:
    INPUT MARKS
    The loop keeps running until the user finally enters a number that lies within the correct range.

Once the user gives a valid number between 0 and 40, the condition becomes false, and the loop ends. The program then displays the message:
OUTPUT “MARKS BETWEEN 0 TO 40 PROVIDED”
This confirms that the user has successfully entered a number within the required range, and the validation is complete.

Let’s take a moment to imagine how this works in a real situation. Suppose the teacher enters 55. The computer checks: “Is 55 less than 0? No. Is 55 greater than 40? Yes.” So the loop runs again and asks the teacher to re-enter a valid number. Suppose the teacher enters –8. Now the computer checks again: “Is –8 less than 0? Yes.” So once again, it asks the teacher to re-enter the marks. The teacher continues trying until they finally enter something like 32. This time the computer sees that 32 is NOT less than 0 and NOT greater than 40—so it accepts the value.

This example clearly shows how range checks prevent invalid data from entering the system. Without this validation, computer programs could store impossible marks like –20 or 200, which could lead to incorrect results, wrong reports, and confusion. Range checks keep data clean, reliable, and accurate.

To summarise, a range check ensures that any number entered by the user falls within a specified limit. If the number goes outside this limit, the system immediately rejects it and asks the user to try again. In our example, we used a WHILE loop to keep checking the marks until the user entered a value between 0 and 40. This is a very common technique used in exams, schools, companies, and almost every system that requires safe and controlled data entry.

You cannot copy content of this page