Bird
Raised Fist0
PLC Programmingscripting~20 mins

Assignment and arithmetic in PLC Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PLC Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of arithmetic assignment in PLC structured text
What is the value of variable Result after executing this PLC structured text code?

VAR
A : INT := 5;
B : INT := 3;
Result : INT;
END_VAR

Result := A + B * 2;
PLC Programming
VAR
  A : INT := 5;
  B : INT := 3;
  Result : INT;
END_VAR

Result := A + B * 2;
A11
B16
C13
D10
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication happens before addition.
💻 Command Output
intermediate
2:00remaining
Result of combined assignment and subtraction
What will be the value of Counter after this code runs?

VAR
Counter : INT := 10;
END_VAR

Counter := Counter - 4 + 2;
PLC Programming
VAR
  Counter : INT := 10;
END_VAR

Counter := Counter - 4 + 2;
A4
B6
C8
D12
Attempts:
2 left
💡 Hint
Calculate subtraction and addition from left to right.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in arithmetic assignment
Which option contains a syntax error in the assignment statement in PLC structured text?
AResult := (A - B) / 2;
BResult := (A + B) * 2;
CResult := A - B / 2;
DResult := A + * B;
Attempts:
2 left
💡 Hint
Look for invalid operator placement.
💻 Command Output
advanced
2:00remaining
Value of variable after mixed arithmetic and assignment
Given the code below, what is the final value of Output?

VAR
X : INT := 4;
Y : INT := 3;
Output : INT;
END_VAR

Output := X * Y - X / Y;
PLC Programming
VAR
  X : INT := 4;
  Y : INT := 3;
  Output : INT;
END_VAR

Output := X * Y - X / Y;
A10
B11
C9
D8
Attempts:
2 left
💡 Hint
Remember integer division truncates decimals.
💻 Command Output
expert
3:00remaining
Final value after sequential arithmetic assignments
What is the final value of Value after running this code?

VAR
Value : INT := 2;
END_VAR

Value := Value + 3;
Value := Value * 2;
Value := Value - 4;
PLC Programming
VAR
  Value : INT := 2;
END_VAR

Value := Value + 3;
Value := Value * 2;
Value := Value - 4;
A6
B8
C10
D4
Attempts:
2 left
💡 Hint
Calculate each assignment step by step.

Practice

(1/5)
1. In PLC programming, which symbol is used to assign a value to a variable?
speed := 100;
easy
A. The ':=' symbol
B. The '=' symbol
C. The '==' symbol
D. The '->' symbol

Solution

  1. Step 1: Understand assignment syntax in PLC

    PLC uses ':=' to assign values to variables, not '=' or '=='.
  2. Step 2: Identify correct assignment operator

    The ':=' operator updates the variable with the new value.
  3. Final Answer:

    The ':=' symbol -> Option A
  4. Quick Check:

    Assignment operator = ':=' [OK]
Hint: Remember ':=' means assign value in PLC [OK]
Common Mistakes:
  • Using '=' instead of ':='
  • Confusing comparison '==' with assignment
  • Using arrow '->' mistakenly
  • Forgetting semicolon after assignment
2. Which of the following is the correct syntax to add 5 to a variable count in PLC?
easy
A. count := count + 5;
B. count = count + 5;
C. count += 5;
D. count :=+ 5;

Solution

  1. Step 1: Check assignment operator usage

    PLC uses ':=' for assignment, so '=' and '+=' are incorrect here.
  2. Step 2: Verify arithmetic addition syntax

    'count := count + 5;' correctly adds 5 to count and assigns it back.
  3. Final Answer:

    count := count + 5; -> Option A
  4. Quick Check:

    Use ':=' for assignment and '+' for addition [OK]
Hint: Use ':=' for assignment, '+' for addition [OK]
Common Mistakes:
  • Using '=' instead of ':='
  • Trying '+=' which is not valid in PLC
  • Writing ':=+' which is invalid
  • Missing semicolon
3. What is the value of result after executing the following PLC code?
temp := 10;
result := temp * 3 + 2;
medium
A. 12
B. 36
C. 30
D. 32

Solution

  1. Step 1: Calculate multiplication first

    temp * 3 = 10 * 3 = 30
  2. Step 2: Add 2 to the multiplication result

    30 + 2 = 32
  3. Final Answer:

    32 -> Option D
  4. Quick Check:

    10 * 3 + 2 = 32 [OK]
Hint: Multiply before adding, follow order of operations [OK]
Common Mistakes:
  • Adding before multiplying
  • Using wrong variable value
  • Ignoring operator precedence
  • Confusing temp and result variables
4. Identify the error in this PLC code snippet:
speed := 50
speed := speed + 10;
medium
A. Cannot add numbers in PLC
B. Using '=' instead of ':='
C. Missing semicolon after first assignment
D. Variable 'speed' not declared

Solution

  1. Step 1: Check statement endings

    PLC statements must end with a semicolon ';'. The first line misses it.
  2. Step 2: Confirm other syntax is correct

    Second line uses correct ':=' and addition syntax.
  3. Final Answer:

    Missing semicolon after first assignment -> Option C
  4. Quick Check:

    Each statement ends with ';' [OK]
Hint: Always end PLC statements with semicolon ';' [OK]
Common Mistakes:
  • Forgetting semicolon
  • Confusing '=' with ':='
  • Assuming addition not allowed
  • Ignoring variable declaration rules
5. You want to calculate the average speed from three sensor readings s1, s2, and s3 in PLC. Which code correctly assigns the average to avg_speed?
s1 := 40;
s2 := 50;
s3 := 60;
avg_speed := (s1 + s2 + s3) / 3;
hard
A. avg_speed = (s1 + s2 + s3) / 3;
B. avg_speed := (s1 + s2 + s3) / 3;
C. avg_speed := s1 + s2 + s3 / 3;
D. avg_speed := (s1 + s2 + s3) * 3;

Solution

  1. Step 1: Check correct assignment operator

    Use ':=' to assign the calculated value to avg_speed.
  2. Step 2: Verify arithmetic expression correctness

    Sum all three readings and divide by 3 inside parentheses for average.
  3. Final Answer:

    avg_speed := (s1 + s2 + s3) / 3; -> Option B
  4. Quick Check:

    Use ':=' and parentheses for correct average [OK]
Hint: Use parentheses to sum before dividing [OK]
Common Mistakes:
  • Using '=' instead of ':='
  • Missing parentheses causing wrong division
  • Multiplying instead of dividing
  • Forgetting semicolon
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard