mrScarlett

Task 1 - PreRelease - 2018

Dec 30th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. INPUT noCows // Input number of cows in a herd
  2.  
  3. cowIds = [1:noCows] // Array to store IDs, the length will be dependent on the noCows input.
  4. totalYield = [1:noCows] // Array to store the total milk from each cow over the 7 days.
  5. idLength = 3 // Constant used for validation of cow ID (the ID length should be 3 numbers)
  6.  
  7. under = [1:noCows]int // Array to store how many times a cow gives less than 12 litres of milk in a day. TASK 3
  8. yieldMin = 12 // Constant used to check if the daily yield for a cow is under 12 litres. TASK 3
  9.  
  10. FOR day = 1 to 7 // Loop for 7 days
  11.  
  12. FOR cow = 1 to noCows // Loop for number of cows
  13. IF day == 1 // If day 1 then the cow ID should be entered,
  14. id=0 // Initialising id to 0 (not 3 digits long)
  15. WHILE length(id) != idLength // Checks if the id length is 3 digits
  16. OUTPUT "Enter Cow ID"
  17. INPUT id // Prompt to enter ID at the beginning as the length is currently 1(id=0)
  18. END WHILE
  19. cowIds[cow] = id //Once the ID entered is 3 digits long then it will be added to the cowsIds array.
  20. under[cow] = 0
  21. totalYield[cow]=0
  22. END IF
  23.  
  24. dailyMilk=0 // dailyMilk set to 0 before loop below
  25. FOR milking = 1 to 2 // loop for 2 milk readings a day
  26. OUTPUT "Milk Reading "+milking
  27. INPUT milkAmount
  28. dailyMilk+=milkAmount // dailyMilk will increase by the milk amount entered above
  29. NEXT milking // milking will increase by 1 each loop
  30.  
  31. totalYield[cow]+=dailyMilk // Increasing the total milk given by the cow in the totalYield array over the 7 days.
  32.  
  33. //This is needed for TASK 3
  34. IF dailyMilk < yieldMin //checking if the milk given in a day by the cow is under 12 litres
  35. under[cow]+=1 // if under 12 litres then increase the under value in the under array for the cow by 1
  36. END IF
  37.  
  38. NEXT cow // cow will increase by 1 with each loop
  39.  
  40. NEXT day // day will increase by 1 with each loop.
Add Comment
Please, Sign In to add comment