You've just been hired at Lighthouse Markets, a reputable (and thoroughly fictional) grocery store chain. One of the primary features of Lighthouse Markets is their recycling program on pop bottles. Here is how the program works:
- For every two empty bottles, you can get one free (full) bottle of pop
- For every four bottle caps, you can get one free (full) bottle of pop
- Each bottle of pop costs $2 to purchase
Given these parameters, write a program so that you can figure out how many total bottles of pop can be redeemed given a customer investment.
Figure out the algorithm that will calculate this. For example, given a $20 investment, the customer will get 10 bottles of pop. That gives a supply of both bottles and bottle caps that can be used to redeem for further bottles, which will then produce a further supply for recycling.
Write a REPL that will prompt the user for the amount (in dollars) that the customer is going to spend. The REPL will then calculate the total number of bottles that the customer will receive and prompt for the next customer's amount.
Enhance the output of your program so that once the amount has been given, it provides a breakdown of how many bottles were purchased, how many were obtained through bottle recycling, and how many were obtained through bottle cap recycling.
Add to the output, so that the program will tell the customer how many bottles and bottle caps they will have left over. We have to upsell the customer on buying more pop after all!
You hear this from us all the time, but build your code incrementally. Build it in small steps, and make sure you are confident and comfortable that the code is functioning correctly before you move on to the next step.
Your use of instance variables for keeping track of different variables will be very important here.
Write this same algorithm using recursion
.