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

  1. Initialize variable total to 100 and display
  2. Execute total += 50 and display result
  3. Execute total -= 30 and display result
  4. Execute total *= 2 and display result
  5. Execute total /= 4 and display result
  6. Execute total %= 7 and 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