Created
March 23, 2011 02:20
-
-
Save sizzlemctwizzle/882495 to your computer and use it in GitHub Desktop.
Pseudocode for how the Qdoba Rewards Program works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sometimes I get bored and write Psuedocode for how random things work | |
// The following is pseudocode for how the Qdoba Rewards Program works | |
// How much money customer owes | |
amountDue = 0; | |
// Customers with Qdoba Cards earn points | |
if (customer.hasCard()) { | |
totalPoints = customer.pointTotal; | |
} | |
// On Tuesdays you get double points | |
pointMultiplier = getDayOfWeek() == "Tuesday" ? 2 : 1; | |
// Use a stack to temporarily store the entrees | |
entrees = new Stack(); | |
// Loop through each menu item that is being purchased | |
for (item in items) { | |
if (customer.hasCard() && item.isEntree()) { | |
// Each entree earns you 100 points (200 on Tues) | |
totalPoints += 100 * pointMultiplier; | |
// Push the entree onto the stack | |
entrees.push(item); | |
} | |
// The price of each item adds to the total | |
amountDue += item.price; | |
} | |
if (customer.hasCard()) { | |
// Keep giving free entree until we're either out of points | |
// or out of entrees being purchased | |
while (totalPoints >= 1100 && !entrees.isEmpty()) { | |
item = entrees.pop(); | |
// Subtract the price of the item from the total | |
amountDue -= item.price; | |
// Subtract the amount of points used towards free entree | |
totalPoints -= 1100; | |
} | |
// Save the new point of the customer | |
customer.pointTotal = totalPoints; | |
} | |
// Add the sales tax to the total | |
amountDue += amountDue * getTaxAsDecimal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment