module.exports = { slug: "tip-and-split-bill", title: "Tip and split a bill", deck_category: "finance", description: "Computes the tip amount, the total bill, and each person's even share when a bill is split among a number of people.", inputs: [ { name: "bill_amount", type: "number", unit: "currency units", required: true, description: "Pre-tip bill amount", min: 0 }, { name: "tip_percent", type: "number", unit: "%", required: true, description: "Tip percentage", min: 0 }, { name: "number_of_people", type: "integer", required: true, description: "Number of people splitting the bill evenly", min: 1 } ], outputs: [ { name: "tip_amount", unit: "currency units", description: "Total tip amount" }, { name: "total_amount", unit: "currency units", description: "Bill plus tip" }, { name: "amount_per_person", unit: "currency units", description: "Even share of the total per person" } ], steps: [ "Convert the tip percent to a decimal: t = tip_percent / 100.", "tip_amount = bill_amount * t.", "total_amount = bill_amount + tip_amount.", "amount_per_person = total_amount / number_of_people.", "Round tip_amount, total_amount, and amount_per_person to 2 decimals (money to cents)." ], constants: [], sources: [ { kind: "url", value: "https://www.consumerfinance.gov/consumer-tools/educator-tools/your-money-your-goals/toolkit/", title: "Your Money, Your Goals: percentage and tip calculation conventions", publisher: "Consumer Financial Protection Bureau", retrieved_utc: "2026-09-30T19:31:29Z", note: "Standard everyday-math tip and even-split convention: tip = bill*rate, per-person = (bill+tip)/people" } ], disclaimer: null, questionText(inputs) { return `A bill of $${inputs.bill_amount} gets a ${inputs.tip_percent}% tip and is split evenly among ${inputs.number_of_people} people. What is the tip, the total, and each person's share?`; }, run(inputs) { const { bill_amount, tip_percent, number_of_people } = inputs; if (typeof bill_amount !== "number" || bill_amount < 0) throw new Error("bill_amount must be a non-negative number"); if (typeof tip_percent !== "number" || tip_percent < 0) throw new Error("tip_percent must be a non-negative number"); if (!Number.isInteger(number_of_people) || number_of_people <= 0) throw new Error("number_of_people must be a positive integer"); const t = tip_percent / 100; const tip_amount = Math.round(bill_amount * t * 100) / 100; const total_amount = Math.round((bill_amount + tip_amount) * 100) / 100; const amount_per_person = Math.round((total_amount / number_of_people) * 100) / 100; return { answer: `Tip $${tip_amount.toFixed(2)}, total $${total_amount.toFixed(2)}, $${amount_per_person.toFixed(2)} per person`, values: { tip_amount, total_amount, amount_per_person } }; }, examples: [ { name: "worked example", inputs: { bill_amount: 84.50, tip_percent: 18, number_of_people: 4 }, expected: { answer: "Tip $15.21, total $99.71, $24.93 per person" }, check: "hand computation: tip = 84.50*0.18 = 15.21; total = 84.50+15.21 = 99.71; per person = 99.71/4 = 24.9275, rounds to 24.93" }, { name: "test vector: single diner, no tip", inputs: { bill_amount: 20, tip_percent: 0, number_of_people: 1 }, expected: { answer: "Tip $0.00, total $20.00, $20.00 per person" }, check: "hand computation: tip = 0.00; total = 20.00; per person = 20.00" } ] };