Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pizza Toppings Program
- // Exemplar Program
- // Edited by programmer name
- // Dare of editing
- // declare the variables used in the program
- global moreToppings // string variable used to indicate whether more toppings are needed
- global topping // character variable used to store topping required
- global toppingList // string variable used to store list of toppings entered
- global numberToppings // integer variable used to store number of toppings entered
- global totalCost // real variable used to store the total cost of the pizza
- global groupSize // integer variable used to store the number of people in the group
- global counter // integer variable used as loop counter and array index
- global names // string array used to store list of names of people in the group
- global randomSelected // integer variable used to store index of randomly selected person
- on mouseUp
- // initialise calculaed values
- put 0 into totalCost
- put "" into toppingList
- // check whether any more toppings are required
- ask "Any toppings required? Answer YES or NO"
- put it into moreToppings
- // loop until no more toppings are required
- repeat until moreToppings = "NO"
- // ask for type of topping required
- ask "Enter the topping required - C, P,M or H"
- put it into topping
- // validate topping entered
- repeat until topping ="C" or topping = "P" or topping ="M" or topping = "H"
- ask "** Only 4 toppings are available. Please make a valid selection **"
- put it into topping
- end repeat
- // concatenate topping to list of toppings
- put toppingLIst & topping into toppingLIst
- // check whether any more toppings are required
- ask "Any more toppings required? Answer YES or NO"
- put it into moreToppings
- end repeat
- // display the list of toppings entered
- put "Pizza toppings selected -" && toppingList & return after field output
- put return after field output
- // calculate the number of toppings entered
- put len(toppingList) into numberToppings
- // calculate the cost of the pizza
- put (numberToppings*0.89) + 8.49 into totalCost
- put "The total cost of the pizza is £" & totalCost & return after field output
- put return after field output
- // ask how many people are int he group
- ask "How many people are in the group?"
- put it into groupSize
- // use a fixed loop to ask for the name of each person in the group
- repeat with counter = 1 to groupSize
- ask "Enter name of person" && counter
- put it into names[counter]
- end repeat
- // select one of the group at random and display their name
- put random(groupSize) into randomSelected
- put "Person selected to receive a free milk shake is" && names[randomSelected] & return after field output
- end mouseUp
Add Comment
Please, Sign In to add comment