0
0
Rustprogramming~15 mins

Relational operators in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Relational Operators in Rust
๐Ÿ“– Scenario: You are building a simple program to compare ages of two friends to see who is older.
๐ŸŽฏ Goal: Learn how to use relational operators in Rust to compare numbers and print the results.
๐Ÿ“‹ What You'll Learn
Create variables with exact values
Use relational operators: ==, !=, <, <=, >, >=
Print boolean results of comparisons
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Comparing values is common in programs that make decisions, like checking user age for access or comparing scores in games.
๐Ÿ’ผ Career
Understanding relational operators is essential for any programming job because they help control the flow of programs and make decisions.
Progress0 / 4 steps
1
Create age variables
Create two variables called alice_age and bob_age with values 25 and 30 respectively.
Rust
Need a hint?

Use let to create variables and assign the exact numbers.

2
Add relational comparisons
Add variables to store the results of these comparisons: alice_age == bob_age in is_equal, alice_age < bob_age in is_alice_younger, and alice_age >= bob_age in is_alice_older_or_equal.
Rust
Need a hint?

Use ==, <, and >= operators to compare the ages and store the results in variables.

3
Add more relational comparisons
Add two more variables: is_not_equal for alice_age != bob_age and is_bob_younger_or_equal for bob_age <= alice_age.
Rust
Need a hint?

Use != and <= operators for these comparisons.

4
Print all comparison results
Print the values of is_equal, is_alice_younger, is_alice_older_or_equal, is_not_equal, and is_bob_younger_or_equal each on a new line using println!.
Rust
Need a hint?

Use println!("{}", variable); to print each boolean value on its own line.