003-004-009
Update Values with Compound Assignment Operators
Medium
Problem Description
Update Values with Compound Assignment Operators
In this problem, you will create a program that reads an initial value and three operation amounts (add, subtract, multiply) from standard input, then updates the value in sequence using +=, -=, and *= compound assignment operators, printing the result after each operation.
Input Format:
initialValue
addAmount
subAmount
mulAmount
Output Format:
After +=: <value after addition>
After -=: <value after subtraction>
After *=: <value after multiplication>
Learning Objectives:
- Understand how compound assignment operators (
+=,-=,*=) work - Write concise code that combines an operation and assignment in one step
- Apply the idioms commonly used in loops and accumulators
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up