0
0
Rubyprogramming~15 mins

Arithmetic operators in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic operators
📖 Scenario: You are helping a small shop owner calculate prices and discounts for products.
🎯 Goal: Build a simple Ruby program that uses arithmetic operators to calculate total price, discount, and final price.
📋 What You'll Learn
Create variables with exact values for product 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 and discounts is common in shops and online stores.
💼 Career
Understanding arithmetic operators is essential for programming tasks involving calculations.
Progress0 / 4 steps
1
Create initial product data
Create a variable called price and set it to 50. Create a variable called quantity and set it to 3.
Ruby
Need a hint?

Use = to assign values to variables.

2
Add discount rate
Create a variable called discount_rate and set it to 0.1 (which means 10%).
Ruby
Need a hint?

Discount rate is a decimal number representing percentage.

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

Use * for multiplication.

4
Print final price after discount
Create a variable called final_price that subtracts discount_amount from total_price. Then print final_price using puts.
Ruby
Need a hint?

Use - to subtract and puts to print.