COS 100: Introduction to Programming

Interim 2021

HW Project 06: Handling money

Due: 01/19 Tue 10pm

Give me neither poverty nor riches—
Feed me with the food allotted to me;
Lest I be full and deny You,
And say, "Who is the Lord?"
Or lest I be poor and steal,
And profane the name of my God.
Proverbs 30:8b–9

Project goal

Create a simple Point of Sale system.

Prerequisites

Project specification

Follow the steps below to write a program that can handle simple tasks for a cashier.
  1. Write a function called ask_for_currency with the following specification:
    • Parameter: a string to be used as a prompt.
    • Ask the user for a number using the prompt passed to this function.
    • This number is a currency amount (such as $34.59) but without the dollar sign in front (such as 34.59).
    • Convert this to an integer number of pennies (such as 3459).
    • Return: the integer number of pennies.
  2. Write a function called format_currency with the following specification:
    • Parameter: a currency amount represented as an integer number of pennies.
    • Convert this number (such as 3459) to a string in the standard way we write currency (such as $34.59), with a dollar sign in front and two decimal places.
    • Return: the string representing the amount.
  3. Write (and call) a main function that asks the user for:
    • the number of items to purchase,
    • the price for each item,
    • the amount tendered,
    and report to the user:
    • the total purchase price,
    • the amount tendered, and
    • the change that's due.

Notes and hints

Suggested order of development

Sample run

Number of items? 2
Price? 20
Price? 14.59
Amount tendered? 40

Report
======
Purchase total: $34.59
Amount tendered: $40.00
Change due: $5.41

Grading

Optional challenge

Start early, have fun, and discuss questions on Moodle.