Back to Challenge Set 4

Code Challenge: Bag Fee

Difficulty  

divider

The Brief

What they asked for
I work the check-in desk and I say the same sentence four
hundred times a shift. Bags over fifty pounds cost seventy-five
dollars extra. Let me type the weight in and have the screen
say it, and tell them how far over they are so they can move
something into their carry-on.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Two outcomes, so this is one if with one else. It does not need a chain.
  • Bag weights are not whole numbers. Pick your parse accordingly.
  • The overweight message has to say how far over, which means a calculation, not just a number you were handed.
  • A bag of exactly fifty pounds must get one answer. Decide which, and write down why in your requirements list. The brief says “over fifty” — read it carefully.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Get the weight and parse it with double.Parse.
  2. Write the if for the overweight case first.
  3. Work out the amount over inside that block. You already know the limit is 50.
  4. Add the else for everything else, then test a bag on each side of the limit.

Sample Output

Sample Output
Bag weight (lbs): 56
Overweight by 6.0 lbs. Fee: $75

A 41-pound bag should say it is within the limit and mention no fee. Test 49, 50, and 51 before you submit — those three are where a boundary mistake shows up.


Submit

Your requirements list and your program file, named cc-bag-fee.

Commence Challenge