Lab 06 10 pts Week 2 Due Apr 13

Lab 06: Eligibility Checker

Multi-branch conditionals, range validation, and compound logic

if-else range-checking compound-conditions validation
Clone from GitHub
3 checkpoints 5 autograder 2 timeliness
Prerequisites: lesson-1-3 lesson-1-9

After this lab, you will be able to:

  • Validate that numeric input falls within an acceptable range
  • Write if/else if/else chains that classify values into categories
  • Combine conditions with && and || to express compound rules
  • Structure conditional logic so that exactly one branch executes

What You’re Building

You will write an eligibility checker that reads a numeric score, validates it, classifies it into a tier (e.g., Bronze, Silver, Gold), and applies a compound-condition modifier. This exercises the full range of conditional logic: input rejection, multi-branch classification, and combined boolean checks. Every branch must print distinct output so the autograder can verify which path executed.


Concepts and Misconceptions

Concept Common Mistake What the Test Catches
Input validation Forgetting to handle invalid input (negative, above max) No rejection message for out-of-range values
else if chain Using separate if statements instead of else if — multiple branches execute Two classification labels printed instead of one
Range boundaries Off-by-one: using > instead of >= at tier boundaries Score at exact boundary gets wrong tier
Compound &&/|| Wrong operator precedence: a || b && c groups as a || (b && c) Modifier applied when it should not be (or vice versa)

Checkpoints

Checkpoint 1: Validate Input Range

What to do: Read an integer score. If it is below 0 or above 100, print an error message (e.g., "Invalid score: must be 0-100") and do not continue to classification. Use an if statement to guard the rest of the program.

What the test checks: For inputs like -5 and 101, only the error message prints. No classification output appears.

Debugging tip: If the test says classification output appeared for an invalid score, your guard clause is not stopping execution. Make sure the classification code is inside the else block, or use return; after printing the error to exit main.

Checkpoint 2: if/else if Chain for Classification

What to do: Classify the validated score into tiers: 90-100 is Gold, 70-89 is Silver, 50-69 is Bronze, 0-49 is Unranked. Use an if/else if/else chain. Print exactly one tier label.

What the test checks: Each score maps to exactly one tier. The test sends boundary values (0, 49, 50, 69, 70, 89, 90, 100) to verify your ranges.

Debugging tip: If a boundary value gets the wrong tier, check whether you used < or <=. For example, if 70 should be Silver, your condition needs >= 70, not > 70. Write the boundary into a test case and run it before submitting.

Checkpoint 3: Compound Condition Modifier

What to do: Add a bonus modifier. If the score is Gold and an additional boolean condition is met (e.g., the user indicates they completed a bonus task), print a modified label like "Gold (with distinction)". Use && to combine the conditions.

What the test checks: The modifier label only appears when both conditions are true. It does not appear for Silver even if the bonus flag is true.

Debugging tip: If the modifier appears for the wrong tier, your && condition is probably attached to the wrong if block. The compound check must be nested inside (or combined with) the Gold branch specifically, not applied globally.


How to Debug

  1. Test every branch. Write down one input that should trigger each branch: Gold, Silver, Bronze, Unranked, invalid-low, invalid-high, Gold-with-modifier, Gold-without-modifier. Run all of them. If you only test happy paths, you will miss boundary bugs.

  2. Use else if, not separate if blocks. If you see two labels printed for one input, your branches are not mutually exclusive. Changing if to else if ensures only the first matching branch runs.

  3. Parenthesize compound conditions. When mixing && and ||, add explicit parentheses: (a >= 90 && a <= 100) && bonus. This removes any ambiguity about evaluation order and makes your intent clear.


Scoring

Component Points Criteria
Checkpoints 3 1 pt each. Binary: the checkpoint test passes or it does not.
Autograder 5 Correctness across all test cases. Partial credit by proportion of tests passed.
Timeliness 2 Full credit if submitted by the due date. 0 if late.
Total 10