Economic order quantity

Tags
Challenge
No

Your company buys Stuffs from wholesalers, and sells it retail. Work out the optimal order quantity. That is, how many Stuffs you should order each time to minimize cost.

Here's some I/O:

  • Sales? 5000
  • Ordering cost? 90
  • Carrying cost? 6
  • Are there Smurfs (Y/N)? n
  •  
  • EoQ: 387

More:

  • Sales? 5000
  • Ordering cost? 90
  • Carrying cost? 6
  • Are there Smurfs (Y/N)? y
  •  
  • EoQ: 388

One more:

  • Sales? some
  • Sorry, you must enter a whole number.
  • Sales? 5000
  • Ordering cost? -3
  • Sorry, ordering cost cannot be less than zero.
  • Ordering cost? 90
  • Carrying cost? something
  • Sorry, you must enter a number.
  • Carrying cost? 6
  • Are there Smurfs (Y/N)? Don't know
  • Please enter Y or N.
  • Are there Smurfs (Y/N)? y
  •  
  • EoQ: 388

Validation rules:

  • Sales (units per year). Must be an integer that is one or greater.
  • Ordering cost ($). The cost of placing one order. Must be a float that is not negative.
  • Carrying cost ($/unit/year). Cost of carrying a unit per year. Storage, insurance, like that. Must be a float that is more than zero.
  • Whether Smurfs are present. After trimming spaces, should be Y or N, though case doesn't matter.

When the data is OK, compute the optimal order quantity, and show it. The formula from Wikipedia is:

Formula

Where:

Variables

If there are Smurfs, add one to the order quantity. They always steal just one.

Upload a zip of your project folder. The usual coding standards apply.

Where referenced