0
0
Cprogramming~20 mins

Increment and decrement operators - Mini Project: Build & Apply

Choose your learning style9 modes available
Increment and Decrement Operators in C
📖 Scenario: Imagine you are managing a small shop's inventory. You need to keep track of the number of items available. Sometimes you add new items, and sometimes items are sold. You will use increment and decrement operators to update the item count quickly.
🎯 Goal: You will create a simple C program that uses increment (++) and decrement (--) operators to update the number of items in stock and then display the final count.
📋 What You'll Learn
Create an integer variable called items with an initial value.
Create an integer variable called restock to hold the number of new items added.
Use the increment operator ++ to increase the items count.
Use the decrement operator -- to decrease the items count.
Print the final value of items.
💡 Why This Matters
🌍 Real World
Increment and decrement operators are used in many programs to update counters, track quantities, or manage loops efficiently.
💼 Career
Understanding these operators is essential for programming jobs that involve managing data, loops, or real-time updates, such as software development and embedded systems.
Progress0 / 4 steps
1
Create the initial item count
Create an integer variable called items and set it to 10 to represent the starting number of items in stock.
C
Need a hint?

Use int items = 10; inside the main function.

2
Add new items to restock
Create an integer variable called restock and set it to 5 to represent new items added to the stock.
C
Need a hint?

Use int restock = 5; inside the main function after items.

3
Update item count using increment and decrement operators
Use the increment operator ++ to increase items by restock times, and then use the decrement operator -- to decrease items by 3 to represent sold items. Use a for loop with variable i to increment items exactly restock times.
C
Need a hint?

Use two for loops: one to increment items restock times, and one to decrement items 3 times.

4
Print the final item count
Use printf to display the final value of items with the message: "Final items in stock: %d\n".
C
Need a hint?

Use printf("Final items in stock: %d\n", items); to show the result.