0
0
Rustprogramming~30 mins

Arithmetic operators in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in Rust
๐Ÿ“– Scenario: You are helping a small shop calculate prices for items bought by customers. You will use arithmetic operators to add, subtract, multiply, and divide numbers.
๐ŸŽฏ Goal: Build a Rust program that uses arithmetic operators to calculate the total price, discount, and final price for a product.
๐Ÿ“‹ What You'll Learn
Create variables with exact values for price and quantity
Create a variable for discount rate
Calculate total price and discount amount using arithmetic operators
Print the final price after discount
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Calculating prices, discounts, and totals is common in shopping apps and billing systems.
๐Ÿ’ผ Career
Understanding arithmetic operations and data types is essential for software development, especially in finance and retail applications.
Progress0 / 4 steps
1
Create initial variables for price and quantity
Create a variable called price with the value 50.0 and a variable called quantity with the value 3.
Rust
Need a hint?

Use let to create variables. Price is a floating-point number, quantity is an integer.

2
Add a discount rate variable
Add a variable called discount_rate with the value 0.1 to represent a 10% discount.
Rust
Need a hint?

Discount rate is a floating-point number between 0 and 1.

3
Calculate total price and discount amount
Create a variable called total_price that multiplies price and quantity. Then create a variable called discount_amount that multiplies total_price and discount_rate.
Rust
Need a hint?

Multiply price and quantity. Convert quantity to f64 to match price type.

4
Print the final price after discount
Calculate the final price by subtracting discount_amount from total_price and print it using println! with the message: "Final price: {final_price}".
Rust
Need a hint?

Subtract discount_amount from total_price. Use println!("Final price: {}", final_price); to show the result.