Home / Questions / Suppose you write a program for computing the perimeter of a rectangle and you mistakenly write your program so that it computes the area of a rectangle. What kind of error is this?
Explanatory Question

Suppose you write a program for computing the perimeter of a rectangle and you mistakenly write your program so that it computes the area of a rectangle. What kind of error is this?

👁 3,581 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

This is a logical error (or semantic error).

Explanation:
  • A logical error occurs when a program runs without crashing but produces incorrect results due to flawed logic.
  • In this case, the mistake is in the formula:
    • Perimeter of a rectangle = 2 * (length + width)
    • Area of a rectangle = length * width
  • Since the program does not crash and still produces an output (though incorrect), it is not a syntax error or runtime error but a logical error.
How to Fix It?

Carefully check the logic and formulas before running the program. Using print statements or a debugger can help identify logical errors. 🚀