z-Shi

N5 Computing Exemplar Livecode: Code

Mar 14th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. // Pizza Toppings Program
  2. // Exemplar Program
  3. // Edited by programmer name
  4. // Dare of editing
  5.  
  6. // declare the variables used in the program
  7. global moreToppings // string variable used to indicate whether more toppings are needed
  8. global topping // character variable used to store topping required
  9. global toppingList // string variable used to store list of toppings entered
  10. global numberToppings // integer variable used to store number of toppings entered
  11. global totalCost // real variable used to store the total cost of the pizza
  12. global groupSize // integer variable used to store the number of people in the group
  13. global counter // integer variable used as loop counter and array index
  14. global names // string array used to store list of names of people in the group
  15. global randomSelected // integer variable used to store index of randomly selected person
  16.  
  17.  
  18. on mouseUp
  19. // initialise calculaed values
  20. put 0 into totalCost
  21. put "" into toppingList
  22.  
  23. // check whether any more toppings are required
  24. ask "Any toppings required? Answer YES or NO"
  25. put it into moreToppings
  26.  
  27. // loop until no more toppings are required
  28. repeat until moreToppings = "NO"
  29. // ask for type of topping required
  30. ask "Enter the topping required - C, P,M or H"
  31. put it into topping
  32.  
  33. // validate topping entered
  34. repeat until topping ="C" or topping = "P" or topping ="M" or topping = "H"
  35. ask "** Only 4 toppings are available. Please make a valid selection **"
  36. put it into topping
  37. end repeat
  38.  
  39. // concatenate topping to list of toppings
  40. put toppingLIst & topping into toppingLIst
  41.  
  42. // check whether any more toppings are required
  43. ask "Any more toppings required? Answer YES or NO"
  44. put it into moreToppings
  45. end repeat
  46.  
  47. // display the list of toppings entered
  48. put "Pizza toppings selected -" && toppingList & return after field output
  49. put return after field output
  50.  
  51. // calculate the number of toppings entered
  52. put len(toppingList) into numberToppings
  53.  
  54. // calculate the cost of the pizza
  55. put (numberToppings*0.89) + 8.49 into totalCost
  56. put "The total cost of the pizza is £" & totalCost & return after field output
  57. put return after field output
  58.  
  59. // ask how many people are int he group
  60. ask "How many people are in the group?"
  61. put it into groupSize
  62.  
  63. // use a fixed loop to ask for the name of each person in the group
  64. repeat with counter = 1 to groupSize
  65. ask "Enter name of person" && counter
  66. put it into names[counter]
  67. end repeat
  68.  
  69. // select one of the group at random and display their name
  70. put random(groupSize) into randomSelected
  71. put "Person selected to receive a free milk shake is" && names[randomSelected] & return after field output
  72.  
  73. end mouseUp
Add Comment
Please, Sign In to add comment