003-004-010
Basic Compound Assignment Operators
Easy
Problem Description
Basic Compound Assignment Operators
In this problem, you will create a program that reads an initial balance, an amount to add, and an amount to subtract from standard input, then uses compound assignment operators (+=, -=) to incrementally update the variable balance and displays the final balance.
Learning Objective: Understand how to use compound assignment operators (+=, -=)
Overview
Read three integers from standard input and use compound assignment operators to efficiently update the variable value.
Input Format
initial_balance
add_amount
subtract_amount
Specifications
- Use the first integer as the initial value of variable
balance - Add the second integer to
balanceusing the+=operator - Subtract the third integer from
balanceusing the-=operator - Output the final balance
Output Format
Balance: <final_balance>
Sample Input/Output
Input:
1000
500
200
Output:
Balance: 1300
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