003-004-012
Running Total with Compound Assignment
Medium
Problem Description
Running Total with Compound Assignment Operators
In this problem: You will create a program that performs running total calculations using compound assignment operators (+=, -=, *=, /=, %=) and displays the result of each step to standard output.
Learning Objective: Understand how compound assignment operators work and learn the concise syntax for updating variable values
Overview
Compound assignment operators shorten a = a + b to a += b. They combine calculation and assignment in a single expression, making code more concise.
Specifications
- Initialize variable
totalto100and display - Execute
total += 50and display result - Execute
total -= 30and display result - Execute
total *= 2and display result - Execute
total /= 4and display result - Execute
total %= 7and display result
Output Format
Initial: 100
After += 50: 150
After -= 30: 120
After *= 2: 240
After /= 4: 60
After %= 7: 4
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