0
0
C++programming~20 mins

Nested conditional statements in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Statements
📖 Scenario: You are creating a simple program to help a store clerk decide discounts based on customer membership and purchase amount.
🎯 Goal: Build a program that uses nested if statements to check if a customer is a member and then check their purchase amount to decide the discount.
📋 What You'll Learn
Create a variable isMember of type bool with value true or false
Create a variable purchaseAmount of type double with a specific value
Use nested if statements to check isMember and then purchaseAmount
Print the correct discount message based on conditions
💡 Why This Matters
🌍 Real World
Stores often give discounts based on membership and purchase amount. This program mimics that decision process.
💼 Career
Understanding nested conditions is important for writing clear decision-making code in many software jobs.
Progress0 / 4 steps
1
Create membership and purchase amount variables
Create a bool variable called isMember and set it to true. Create a double variable called purchaseAmount and set it to 120.0.
C++
Need a hint?

Use bool for true/false and double for decimal numbers.

2
Add a discount threshold variable
Create a double variable called discountThreshold and set it to 100.0.
C++
Need a hint?

This variable will help decide if the purchase amount qualifies for a discount.

3
Write nested if statements to check membership and purchase amount
Write nested if statements: first check if isMember is true. Inside it, check if purchaseAmount is greater than discountThreshold. If both are true, set a string variable discountMessage to "You get a 20% discount!". Otherwise, set discountMessage to "No discount available.". If isMember is false, set discountMessage to "Join our membership for discounts!".
C++
Need a hint?

Remember to include #include <string> at the top to use std::string.

4
Print the discount message
Write a std::cout statement to print the discountMessage variable.
C++
Need a hint?

Use std::cout << discountMessage << std::endl; to print the message.