Challenge one: Hope in our hearts
The menu items picked will be based on an algorithm, which asks the customer to choose a number and then calculates what to give them.
Here is how the chef works out what to give the customer:
- Lay out all the foods in a line on the table, out of sight of the customer.
- Ask the customer for a number. This can be any number except 0 or the number of things on the table. Call this number 'n' (the offset).
- Show the choices to the customer.
- Ask the customer what they hate most
- Starting from the food they hate, move along the foods by 'n' places. If this goes over the line of things on the table, walk back to the start of the line of foods and keep counting along until you get to the 'n'th food.
- That is what they get to eat.
- The same procedure is followed for the starter, main course, and pudding.
Write a program following the algorithm above to select from these possible choices:
Starters: Soup, Salad, Mushrooms, Whitebait, Bruschetta, Avocado, Prawns, Olives, Bread, Doughballs
Mains: Chicken, Steak, Pizza, Risotto, Pasta, Salad, Pie, Casserole, Pork, Lasagne
Puddings: Fruit, Ice Cream, Sorbet, Crumble, Cheese, Rice Pudding, Tiramisu, Trifle, Cheesecake, Apple Pie
Here is the lists in a format you might find convenient...
'Soup', 'Salad', 'Mushrooms', 'Whitebait', 'Bruschetta', 'Avocado', 'Prawns', 'Olives', 'Bread', 'Doughballs'
'Chicken', 'Steak', 'Pizza', 'Risotto', 'Pasta', 'Salad', 'Pie', 'Casserole', 'Pork', 'Lasagne'
'Fruit', 'Ice Cream', 'Sorbet', 'Crumble', 'Cheese', 'Rice Pudding', 'Tiramisu', 'Trifle', 'Cheesecake', 'Apple Pie'
Requirements
- The program should ask for the customer's name
- The program should ask for the number once (all lists have 10 items, so the same number is valid for all).
- It should keep asking until a valid number is given.
- For each of starter, main and pudding it should
- Show a list of the options
- Allow the customer to select which one they don't want - only accept a choice which is in the list.
- Store in a variable the food the customer will be given by moving 'n' places up the list of foods
- The program should display on the screen a personalised message saying what food has been selected.
- Once completed, the program should start again for the next customer.
Marks |
Tests |
Ask for the customer's name (1) |
Show it rejecting a blank name
Show it accepting a non-blank name
|
Ask for the customer's number (2) |
Show it rejecting a non numeric value
Show it rejecting zero
Show it rejecting 10 (the size of the list)
Show it accepting a valid value
|
Display the list of starters (1) |
Prove that was done
|
Display the list of mains and puddings (1) |
Prove that was done
|
Ask the customer to choose a starter (2) |
Show it rejecting blank
Show it rejecting something not in the list
Show it accepting something on the list
|
Choose the starter they will have (4) |
Choose offset number '3' and a food at the start of the starters list
Show displaying the message to the customer
Prove that the food selected is indeed 'n' places further up the starters list
Choose offset number '3' and the last food in the starters list
Show displaying the message to the customer
Prove that the food selected is indeed 'n' places further up the starters list, and that is has wrapped round.
|
Choose the main (4) and pudding (4) they will have |
Either:
Repeat the starters tests for mains and puddings
OR
Demonstrate that your code uses a function with parameters to calculate the food chosen, and so will always work for mains and puddings if it works for starters.
|
|