0
0
C++programming~15 mins

Relational operators in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Relational Operators Practice
📖 Scenario: You are helping a store manager compare product prices to decide which items are cheaper or more expensive.
🎯 Goal: Build a simple C++ program that uses relational operators to compare two product prices and shows the comparison results.
📋 What You'll Learn
Create two variables to store product prices
Create a variable to hold a threshold price
Use relational operators to compare prices with each other and with the threshold
Print the results of the comparisons
💡 Why This Matters
🌍 Real World
Comparing prices helps shoppers and store managers decide which products are cheaper or more expensive.
💼 Career
Understanding relational operators is essential for decision-making logic in programming jobs like software development and data analysis.
Progress0 / 4 steps
1
Create product price variables
Create two double variables called price1 and price2 with values 19.99 and 24.99 respectively.
C++
Need a hint?

Use double type for prices and assign the exact values.

2
Add a threshold price variable
Create a double variable called threshold and set it to 20.00.
C++
Need a hint?

Use double type and assign the exact value 20.00.

3
Compare prices using relational operators
Use relational operators to create four bool variables: isPrice1Less for price1 < price2, isPrice2Greater for price2 > price1, isPrice1BelowThreshold for price1 < threshold, and isPrice2AboveThreshold for price2 > threshold.
C++
Need a hint?

Use < and > operators to compare the variables exactly as named.

4
Print the comparison results
Print the four boolean variables isPrice1Less, isPrice2Greater, isPrice1BelowThreshold, and isPrice2AboveThreshold each on a new line using std::cout. Print true or false for each value.
C++
Need a hint?

Use std::cout and the ternary operator to print true or false for each boolean variable.