'F' → Fullscreen
You are writing a program that works out how much pizza to order. It asks three questions and answers in two sentences.
Before you open VS Code. On your sheet, write down:
Then work out one example by hand: 9 people, 3 slices each, 8 slices per pizza. Write the answer on your sheet before the computer tells you.
Copy template-console to 1-06-pizza. Write only the asking, and print the three answers straight back:
io.write("How many people? ")local people = tonumber(io.read())
io.write("Slices each? ")local slicesEach = tonumber(io.read())
io.write("Slices per pizza? ")local perPizza = tonumber(io.read())
print(people)print(slicesEach)print(perPizza)How many people? 9 [Enter]Slices each? 3 [Enter]Slices per pizza? 8 [Enter]938Run it. Three numbers in, the same three numbers out. That is all this step has to prove, and it is worth proving before anything depends on it.
Delete the three plain print lines and put the real work in their place:
io.write("How many people? ")local people = tonumber(io.read())
io.write("Slices each? ")local slicesEach = tonumber(io.read())
io.write("Slices per pizza? ")local perPizza = tonumber(io.read())
local total = people * slicesEachlocal pizzas = math.floor(total / perPizza)local extra = total % perPizza
print("You need " .. total .. " slices.")print("That is " .. pizzas .. " whole pizzas plus " .. extra .. " slices.")How many people? 9 [Enter]Slices each? 3 [Enter]Slices per pizza? 8 [Enter]You need 27 slices.That is 3 whole pizzas plus 3 slices.Compare that against the answer you worked out by hand in task 1. If they disagree, one of you is wrong and it is worth finding out which.
Run it four more times and write every result on your sheet before you run it:
| People | Slices each | Per pizza | Why this one |
|---|---|---|---|
| 16 | 2 | 8 | Divides exactly |
| 1 | 3 | 8 | Not even one pizza |
| 0 | 3 | 8 | Nobody came |
| 4 | 2 | 1 | Very small pizzas |
How many people? 16 [Enter]Slices each? 2 [Enter]Slices per pizza? 8 [Enter]You need 32 slices.That is 4 whole pizzas plus 0 slices.Three of those four are arithmetically correct and read badly. Find them, and for each one write down what a person would rather have been told.
The program says 3 whole pizzas plus 3 slices, but nobody sells three slices. Add a line that says how many pizzas to order so that everybody gets fed.
You have the tools already. The hard part is that the answer is not always pizzas + 1 — test it with 16 people at 2 slices each and see.
Copy the template to 1-06-mine and write a program of the same shape about something you care about — splitting a bill, minutes of practice per week, how many packs of cards to buy, how much of a video game you have finished.
Three questions, real arithmetic, and an answer in a full sentence. Test it with zero and with one.
1-06-pizza asks three questions and answers in two sentencesAnswer the following questions before submitting your work.
Submit the required files to the appropriate dropbox.