Increment and Decrement Operators
📖 Scenario: You are helping a cashier count the number of items in a shopping cart. Sometimes items are added, and sometimes items are removed. You will use increment and decrement operators to keep track of the count.
🎯 Goal: Build a simple C++ program that uses increment (++) and decrement (--) operators to update the count of items in a cart.
📋 What You'll Learn
Create an integer variable
itemCount with an initial value.Create an integer variable
itemsAdded to represent how many items are added.Use the increment operator
++ to increase itemCount by itemsAdded times.Use the decrement operator
-- to decrease itemCount by 1 for each item removed.Print the final value of
itemCount.💡 Why This Matters
🌍 Real World
Increment and decrement operators are used in many programs to count things, like items in a cart, steps in a process, or scores in a game.
💼 Career
Understanding these operators is essential for writing efficient loops and managing counters in software development jobs.
Progress0 / 4 steps