Bird
0
0

You want to write a program that prints "Adult" if age is 18 or more, "Teen" if age is between 13 and 17, and "Child" otherwise. Which code correctly uses conditional logic?

hard📝 Application Q8 of 15
C - onditional Statements
You want to write a program that prints "Adult" if age is 18 or more, "Teen" if age is between 13 and 17, and "Child" otherwise. Which code correctly uses conditional logic?
Aif (age >= 18) { printf("Adult"); } if (age >= 13) { printf("Teen"); } else { printf("Child"); }
Bif (age >= 18) { printf("Adult"); } else if (age >= 13) { printf("Teen"); } else { printf("Child"); }
Cif (age > 18) { printf("Adult"); } else if (age > 13) { printf("Teen"); } else { printf("Child"); }
Dif (age >= 18) { printf("Adult"); } else if (age <= 17) { printf("Teen"); } else { printf("Child"); }
Step-by-Step Solution
Solution:
  1. Step 1: Check the age ranges and conditions

    Adult is age 18 or more, Teen is 13 to 17, Child is below 13.
  2. Step 2: Evaluate each option's conditions

    if (age >= 18) { printf("Adult"); } else if (age >= 13) { printf("Teen"); } else { printf("Child"); } correctly checks age >= 18, then age >= 13 (which means 13-17), else Child. Others have wrong operators or missing else if.
  3. Final Answer:

    if (age >= 18) { printf("Adult"); } else if (age >= 13) { printf("Teen"); } else { printf("Child"); } -> Option B
  4. Quick Check:

    Use else if for multiple ranges [OK]
Quick Trick: Use else if for multiple conditions [OK]
Common Mistakes:
  • Using separate ifs instead of else if
  • Wrong comparison operators
  • Incorrect order of conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes