lists can help users understand options available and then select one
Pizza Toppings: calculate a total cost of options
pizza delivery companies allow customers to create their own combinations of toppings
requirement
The program should store list of 5 pizza toppings and present them to a customer as options. The user should be able to respond to each option by entering true to include the topping and false to leave it out. The program should finally display the list of toppings requested and the total cost. The cost, in pence, includes the pizza-base (90) and a fixed price (35) for each pizza-topping.
chosenOptions is initialised with the base, the names of selected toppings will be joined on the end
the user's response, typed at the keyboard, is stored as a boolean
when the boolean is true (customer wants the topping), the cost is updated and the name of the topping in the array is joined on to the chosenOptions text
toppings[i] identifies the array and the position of the element (topping) to be used, i is the position of the next element, starting at 0 and finishing at 4
program code
Loading…
PRIMM
predict
what will the output be if a customer responds false to every option?
what will the output be if a customer responds true to every option?
what would happen if you swapped the position of chosenOptions and toppings[i] variables in the line which updates chosenOptions
run
Try the text values as shown below before running the program with your own choices
swap the position of chosenOptions and toppings[i] in the line which updates chosenOptions
the condition used to check the user's response is (toppingOption == true),
this could be changed to (!(toppingOption == false)), make the change and test that the result is the same, can you explain why?
modify
mod1
The boolean variable toppingOption could be switched to be an integer variable with an initial value of 0. The user can then enter 0, 1 or another quantity instead of true or false. The program should treat a 0 like false and any other number as quantity for that topping, for example 2 for mozzarella is double cheese! The code for updating the cost will need to be changed also.
Do you want this topping? : mozzarella : 2
Do you want this topping? : pepperoni : 0
Do you want this topping? : mushroom : 0
Do you want this topping? : olives : 0
Do you want this topping? : chicken : 0
options selected: pizza base, mozzarella (x2)
total cost is 165
make : skating points
In a skating competition nine judges award points which are added to produce a total
requirement
The program should allow the user to enter and store a set of nine scores, one from each judge. The total should be calculated but no yet shown. Then the program should ask for the name of each judge in turn and display the judge's name along with the score given by the judge.
Sample output
Enter the score for judge 1: 28.9
Enter the score for judge 2: 30.5
..
Enter the score for judge 8: 31.2
Enter the score for judge 9: 29.4
Enter the name for judge 1: Gillis
Judge Gillis awarded a score of 28.9
Enter the name for judge 2: Evgeni
Judge Evgeni awarded a score of 30.5
..
Enter the name for judge 8: Sonja
Judge Sonja awarded a score of 31.2
Enter the name for judge 9: Irina
Judge Irina awarded a score of 29.4
The final score is 287.3
design
store
list of 9 scores after they are entered
input
list of 9 scores
names of the 9 judges
output
the name of each judge and the score awarded by the judge
the final total score
process
calculate the final score as a running total, adding up each of the 9 judges scores
algorithm
0. initialise total score
1. loop for each score with index = 0 to 8
2. ask user to enter the score given by the next judge
3. update the total score: add on the score intput by the user
4. end loop
5. loop for each score with index = 0 to 8
6. ask user to enter the name of the next judge
7. display the judges name and the score stored for that judge