Challenge 2: Things get better and better
Edgar has recently come across the theory of Nominative Determinism. This says that a person's actions in life (e.g. their job) is to some extent determined by their name. For example, there are dentists called Mr Payne, Belgian footballer Mark De Man, the Vicar Mr Sermon... And so on.
A new system will now be devised, where instead of choosing a number, the first three letters of the customer's name will be used as the 'offset' for their starter, main and pudding. So A=1, B=2 C=3 etc. While it is now possible that they may get the meal they hate most (if their letter happened to give them a number which was the same as the number of choices), that is just fate really.
Take a copy of your program for challenge 1 and adapt it so that:
- The program should ask for the customer's name
- Do not ask for their number, instead:
- Store the position in the alphabet of the first letter of the name as 'starter_offset'
- Store the position in the alphabet of the second letter of the name as 'main_offset'
- Store the position in the alphabet of the third letter of the name as 'pudding_offset'
Hint: If you know the ASCII value of the letter, and knowing that 'A' has ASCII value 65, you can easily work out the position in the alphabet of any letter - especially if you make sure to convert everything to upper case.
- Change your code which selects the starters, mains and puddings so that it uses these new variables
- Tell the customer what offset values are being used
|Calculate the offsets (6)
||Show that customer 'Abbi McAbbeville' has offsets of 1,2 and 2|
Show that customer 'Ben Benson' has offsets of 2,5 and 14
|Use the offsets (4)
||Show that customer 'Abbi McAbbeville' choosing starters, mains and puddings gets the correct food|
Show that customer 'Ben Benson' choosing starters, mains and puddings gets the correct food