0
0
C Sharp (C#)programming~15 mins

Assignment and compound assignment in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Assignment and Compound Assignment in C#
📖 Scenario: You are helping a small shop owner keep track of the number of items in stock. You will use simple assignment and compound assignment to update the stock count as items are added or sold.
🎯 Goal: Build a small C# program that creates a stock count variable, updates it using assignment and compound assignment operators, and then prints the final stock count.
📋 What You'll Learn
Create an integer variable called stockCount with an initial value of 50.
Create an integer variable called newShipment with a value of 20.
Use the assignment operator = to set stockCount to 50.
Use the compound assignment operator += to add newShipment to stockCount.
Use the compound assignment operator -= to subtract 15 from stockCount.
Print the final value of stockCount.
💡 Why This Matters
🌍 Real World
Keeping track of stock counts is important for shops to know how many items they have available.
💼 Career
Understanding assignment and compound assignment is a basic skill for programming jobs that involve data updates and calculations.
Progress0 / 4 steps
1
Create the initial stock count
Create an integer variable called stockCount and set it to 50.
C Sharp (C#)
Need a hint?

Use int to declare a whole number variable and = to assign the value.

2
Add new shipment count
Create an integer variable called newShipment and set it to 20.
C Sharp (C#)
Need a hint?

Declare another integer variable and assign it the value 20.

3
Update stock count with compound assignment
Use the compound assignment operator += to add newShipment to stockCount.
C Sharp (C#)
Need a hint?

Use stockCount += newShipment; to add and assign in one step.

4
Subtract sold items and print final stock
Use the compound assignment operator -= to subtract 15 from stockCount. Then print stockCount using Console.WriteLine.
C Sharp (C#)
Need a hint?

Use stockCount -= 15; to subtract 15. Then print with Console.WriteLine(stockCount);.