0
0
Rustprogramming~15 mins

Immutable variables in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Immutable variables
๐Ÿ“– Scenario: Imagine you are writing a program to store the number of days in a week. This number should never change because it is a fixed fact.
๐ŸŽฏ Goal: You will create an immutable variable to hold the number of days in a week, then try to use it in a simple calculation.
๐Ÿ“‹ What You'll Learn
Create an immutable variable named days_in_week with the value 7.
Create another variable named weeks with the value 3.
Calculate the total number of days in weeks weeks using days_in_week.
Print the total number of days.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Immutable variables are used to store fixed values that should not change, like constants or configuration values.
๐Ÿ’ผ Career
Understanding immutability is important for writing safe and predictable Rust programs, which is valuable in systems programming and software development.
Progress0 / 4 steps
1
Create an immutable variable
Create an immutable variable called days_in_week and set it to 7.
Rust
Need a hint?

Use let without mut to make the variable immutable.

2
Add a variable for weeks
Add a variable called weeks and set it to 3 inside the main function, below days_in_week.
Rust
Need a hint?

Use let weeks = 3; to create the variable.

3
Calculate total days
Create a variable called total_days that multiplies days_in_week by weeks inside the main function.
Rust
Need a hint?

Use let total_days = days_in_week * weeks; to calculate the total.

4
Print the total days
Print the value of total_days using println! inside the main function.
Rust
Need a hint?

Use println!("Total days: {}", total_days); to print the result.