Add four measured values
Practise arrays on four readings before you build a filter.
Copy SampleA, SampleB, SampleC and SampleD into Values[0] to Values[3]. Then add them up into Total, a (decimal number). Do this fresh on every .
Pro missionTotal follows new readings, decimals included
Test 1 of 5SampleAFirst reading0 %SampleBInput0SampleDLast reading0 %TotalFour-reading total0 %- Level
- Applied
- Time
- About 12 min
- Reward
- +150 XP
- Rig
- 3D process tank
- Siemens editors
- SCL
- Rockwell editors
- Structured Text
- Course stage
- 17. Work through a collection
What the tests check
- Total adds all four values exactly once, decimals included.
- When an changes, Total updates at once. If nothing changes, Total must not keep growing.
- The worked solution uses slots 0 to 3 and a FOR loop that includes both ends.
- Try it Use the buttons below the model and watch the rig respond.
- Test solution Every check runs on your code in one press.
- Replay If one fails, step through it one scan at a time to see why.
Where you’d see this on site
At a drinks factory, a daily report adds up water-use readings from four meters. All four readings must be in the total.
Missing one reading gives a false total. Counting one twice also misleads the operator. This exercise only does the sums; it does not fill the tank.
At a drinks factory, valves let measured amounts of water and syrup into a mixing tank. An electric mixer blends them into one batch. An outlet valve then sends the drink to a holding tank. Filling machines bottle it from there.
- Ingredient tanksHold the water and syrup
- Mixing tankFill, mix and measure one batchYou are here
- Holding tankKeeps the finished drink ready
- Bottle fillerPuts the drink into bottles
On a real site: places, parts and safety
- Drinks factory — blending water and syrup
- Paint factory — mixing ingredients into a consistent colour
- Water-treatment works — preparing a measured chemical mixture
- Brewery — heating water for washing equipment
A full tank does not close its own inlet. Water keeps arriving until the valve closes, so an open inlet can flood the room.
A heater that is not covered by liquid can overheat. Real tanks have separate safety devices as well as the PLC programme.
The sizes, timings and cutaways are teaching choices, not a drawing of any one real installation.
Next in the course
- Average the last N readingsSmooth a noisy level. Average only the readings you have, and drop the oldest.Applied · 25 min · +300 XP
- Describe one pump with a structureKeep a pump’s data together under one tag name.Applied · 12 min · +150 XP
- Call one block for two pumpsOne block, two copies, each with its own memory.Advanced · 20 min · +300 XP
- Read a 4–20 mA transmitterTurn raw input counts into a level the operator can trust.Applied · 15 min · +250 XP