LearnFrenzy
Sign in Take a free test

Decision Making · Find the Error · Question 1

Bug: an age range check that is always true Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

Applicants must be 18 to 60 years old. What does the program print for age 70, and why?

main.c
#include <stdio.h>

int main(void) {
    int age = 70;
    if (age >= 18 || age <= 60)
        puts("eligible");
    else
        puts("not eligible");
    return 0;
}
  • A not eligible
  • B eligible – with ||, every age satisfies one side; it must be age >= 18 && age <= 60 Correct
  • C Nothing
  • D It does not compile
Correct Answer: Option B

70 ≥ 18, so the whole || is true. A range needs both bounds: &&. Compilers often warn that such overlapping comparisons are always true.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links