APPLYING MATH IN A
BUSINESS POINT OF VIEW
What happens when a program gets too long? Imagine a day at a typical restaurant or shop and you think to yourself, if I can get my program to perform mathematical calculations for me, surely it can help me come up with some sort of receipt for customers who purchase things in store. However, throughout the day, if your business location happens to be at the core of downtown, writing 4 lines of code for hundreds of customers will probably get you to writing more than enough lines for the day.
Can we tell a program to repeat itself? Simply put, the answer is YES!
Can we tell a program to repeat itself? Simply put, the answer is YES!
Here is a program that shows an example representation of how a business is run. Usually, the more a customer buys the better deal they get.
Step 1: Start by declaring your different types of variables and set up what you want your customer to know about your sale. Step 2: Declare your ranges that you've indicated in your written portion to your customers about your sales so that user input within a given range will output the correct amount. Step 3: Create a formula that uses the dependent Subtotal variable and the tax rate of your home province to generate the taxes needed to be charged. Step 4: Write lines that display your calculated results accurate to 2 decimal places because we're talking about money. |
Repeat Command:Going back to the sandwich analogy. Once you've figured out the part of the program that you want to run continuous, contain the program within the commands "repeat" "until false".
By now you should have realized that if the user tries to input a partial number, the computer aborts the program and the user must start all over. This is because the declared variable is an integer and not a real number. Therefore it needs to be a whole answer. The same thing goes for the repeat until false command: If you try entering a letter in to the input field the program will abort and give you an error message. |
Assignment 4:
Choose an item to sell and create a program that offers users 3 buying choices and price differences. Calculate the subtotal of the quantity that your customer wants to purchase along with the GST, PST, and the final grand total. The program must be able to replicate itself infinitely as long as a valid input is given. Out of 10 marks: See Skills Mastery List on the right. |
Skills Mastery List:
|