0
0
Rustprogramming~15 mins

Assignment operators in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Assignment operators
๐Ÿ“– Scenario: You are managing a small shop's inventory. You want to update the stock counts quickly using assignment operators.
๐ŸŽฏ Goal: Learn how to use assignment operators like +=, -=, *=, and /= in Rust to update variables efficiently.
๐Ÿ“‹ What You'll Learn
Create variables with initial stock counts
Create a variable for the number of items sold
Use assignment operators to update stock counts
Print the final stock counts
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Assignment operators help update values quickly in programs like inventory management, budgeting apps, or games.
๐Ÿ’ผ Career
Understanding assignment operators is essential for writing clean and efficient code in any programming job.
Progress0 / 4 steps
1
Create initial stock variables
Create three variables called apples, bananas, and oranges with values 50, 30, and 20 respectively.
Rust
Need a hint?

Use let mut to create variables that can change later.

2
Create a variable for sold items
Create a variable called sold and set it to 5 to represent items sold.
Rust
Need a hint?

This variable does not need to change, so no mut needed.

3
Update stock using assignment operators
Use assignment operators to subtract sold from apples and bananas, and multiply oranges by 2.
Rust
Need a hint?

Use -= to subtract and *= to multiply and assign.

4
Print the final stock counts
Print the values of apples, bananas, and oranges using println! with the format: "Apples: {}", "Bananas: {}", and "Oranges: {}".
Rust
Need a hint?

Use println!("Text: {}", variable); to print variables with text.