Scenario Based Coding Problems on Nested if-else in C++

Nested if else scenario based questions in C++

Once you grab the concept of nested if-else in C++, the next step is to solve some fun and interesting scenario-based challenges. These nested if-else problems will test your problem-solving skills and logical thinking. Each scenario is designed to mimic real-world decision-making, making coding both practical and engaging. Let’s see how well you can navigate through these coding puzzles and unlock the solutions!

Parking Fee Calculation

Parking Fee scenario program in C++ using nested if-else statements
Imagine you’re managing a parking lot, and you need to calculate parking fees based on the type of vehicle and how long it’s parked. The parking fees differ depending on whether the vehicle is a car or a motorcycle and how many hours it has been parked:
For Cars:
If the car is parked for 1 to 3 hours, the fee is $5 per hour.
If the car is parked for more than 3 hours, the fee is reduced to $4 per hour.
For Motorcycles:
If the motorcycle is parked for 1 to 2 hours, the fee is $3 per hour.
If the motorcycle is parked for more than 2 hours, the fee is reduced to $2 per hour.
For any other vehicle or parking time, the fee is $0.

Test Cases:
Input: Vehicle type: Car, Hours parked: 4
Output: Parking Fee: $16
Input: Vehicle type: Motorcycle, Hours parked: 1
Output: Parking Fee: $3

Explanation:

  • User Input: Enter the number of hours the vehicle was parked.
  • First Condition: If the parking time is up to 2 hours:
    • The fee is $5.
  • Nested Condition: If the parking time is more than 2 hours but up to 5 hours:
    • The base fee is $5.
    • An additional fee of $2 is charged for every hour after the first 2 hours.
  • Nested Condition: If the parking time exceeds 5 hours:
    • The base fee is $11 (for the first 5 hours).
    • An additional fee of $3 is charged for every hour after the first 5 hours.
  • Output: Displays the calculated parking fee based on these conditions.

This method ensures the correct parking fee is calculated depending on how long the vehicle was parked, with more detailed charges for longer parking times.

#include <iostream>
using namespace std;

int main() {
    string vehicleType;
    int hoursParked;
    double fee;
    cout << "Enter the vehicle type (Car, Motorcycle): ";
    cin >> vehicleType;
    cout << "Enter the number of hours parked: ";
    cin >> hoursParked;

    if (vehicleType == "Car") {
        if (hoursParked > 3) {
            fee = hoursParked * 4;
        } else if (hoursParked >= 1) {
            fee = hoursParked * 5;
        } else {
            fee = 0;
        }
    } else if (vehicleType == "Motorcycle") {
        if (hoursParked > 2) {
            fee = hoursParked * 2;
        } else if (hoursParked >= 1) {
            fee = hoursParked * 3;
        } else {
            fee = 0;
        }
    } else {
        fee = 0;
    }

    cout << "Parking Fee: $" << fee << endl;
    return 0;
}

Car Loan Approval

Car Loan Approval calculator program in C++ using nested if-else statements
You are working at a bank, and the approval of a car loan depends on the applicant’s income and credit score:
If the income is above $50,000 and the credit score is above 700, approve the loan.
If the income is between $30,000 and $50,000 and the credit score is between 600 and 700, approve the loan with conditions.
If the income is below $30,000 or the credit score is below 600, reject the loan.
Test Cases:
Input:
Income = $55,000,
Credit Score = 720
Output:
Loan Approval: Approved
Input:
Income = $25,000,
Credit Score = 580 Output:
Loan Approval: Rejected

Explanation:

  • The program evaluates loan approval based on two factors: income and credit score.
  • First, it checks if the income is greater than 50,000. If true, the program then checks the credit score:
    • If the credit score is above 700, the loan is approved.
    • Otherwise, if the score is 700 or below, the loan is rejected.
  • If the income falls between 30,000 and 50,000, the program checks the credit score again:
    • If the credit score is between 600 and 700, the loan is approved with conditions.
    • If the score is outside that range, the loan is rejected.
  • For incomes below 30,000, the loan is automatically rejected, regardless of credit score.
#include <iostream>
using namespace std;

int main() {
    int income, creditScore;
    cout << "Enter your income: ";
    cin >> income;
    cout << "Enter your credit score: ";
    cin >> creditScore;

    if (income > 50000) {
        if (creditScore > 700) {
            cout << "Loan Approval: Approved\n";
        } else {
            cout << "Loan Approval: Rejected\n";
        }
    } else if (income >= 30000 && income <= 50000) {
        if (creditScore >= 600 && creditScore <= 700) {
            cout << "Loan Approval: Approved with conditions\n";
        } else {
            cout << "Loan Approval: Rejected\n";
        }
    } else {
        cout << "Loan Approval: Rejected\n";
    }

    return 0;
}

Exam Eligibility

Attendance checking scenario program image using nested if else in C++
A university requires a minimum of 75% attendance to allow students to sit for the final exam. However, students with attendance between 65% and 74% can attend if they provide a valid medical certificate. Students with less than 65% attendance cannot attend the exam.
Attendance >= 75%: Eligible
Attendance between 65% and 74% with a medical certificate: Eligible
Attendance < 65%: Not eligible

Test Case:
Input: 80
Output: Eligible for the exam
Input: 70, Yes (Medical Certificate)
Output: Eligible for the exam

Explanation:

  • The program takes the attendance percentage as input.
  • It first checks if the input is valid (0-100%).
  • If attendance is 75% or above, the student is eligible for the exam.
  • If attendance is between 65% and 74%, it asks if the student has a medical certificate. If yes, they are eligible; otherwise, they are not.
  • If attendance is less than 65%, the student is not eligible.
  • If the attendance is invalid (out of range), an error message is shown.
#include <iostream>
using namespace std;

int main() {
    int attendance;
    char medical;
    cout << "Enter attendance percentage: ";
    cin >> attendance;

    if (attendance >= 0 && attendance <= 100) {
        if (attendance >= 75) {
            cout << "Eligible for the exam\n";
        } else if (attendance >= 65) {
            cout << "Do you have a medical certificate? (Y/N): ";
            cin >> medical;
            if (medical == 'Y' || medical == 'y') {
                cout << "Eligible for the exam\n";
            } else {
                cout << "Not eligible for the exam\n";
            }
        } else {
            cout << "Not eligible for the exam\n";
        }
    } else {
        cout << "Invalid attendance percentage!\n";
    }
    return 0;
}

Sports Team Selection

Sports selection scenario program in C++ using nested if-else statements
You are the head coach for a local sports club, where young athletes come to develop their skills. It’s your job to place each new player into the appropriate team for training. The teams are organized by gender and age group to ensure fair competition and tailored training. The club offers two divisions: Junior teams for players under 18, and Senior teams for players 18 and older. You need to assign each player to the correct team based on their gender and age.
If a player is male and under 18, they belong to the “Junior Boys Team.”
If a player is male and 18 or older, they belong to the “Senior Boys Team.”
If a player is female and under 18, they belong to the “Junior Girls Team.”
If a player is female and 18 or older, they belong to the “Senior Girls Team.”
Your task is to automate this process using a program that checks both the gender and age of the player and assigns them to the appropriate team.

Test Cases:
Input: Gender: Male, Age: 17
Output: Junior Boys Team
Input: Gender: Female, Age: 19
Output: Senior Girls Team

Explanation:

  • The program asks the user to input the gender and age of the player.
  • It checks if the gender is “Male.”
    • If the age is below 18, the player is assigned to the “Junior Boys Team.”
    • If the age is 18 or above, the player is assigned to the “Senior Boys Team.”
  • If the gender is “Female,”
    • If the age is below 18, the player is assigned to the “Junior Girls Team.”
    • If the age is 18 or above, the player is assigned to the “Senior Girls Team.”
  • If the user inputs an invalid gender, the program outputs an error message.
#include <iostream>
using namespace std;

int main() {
    string gender;
    int age;

    cout << "Enter gender (Male/Female): ";
    cin >> gender;
    cout << "Enter age: ";
    cin >> age;

    if (gender == "Male") {
        if (age < 18) {
            cout << "Team: Junior Boys Team\n";
        } else {
            cout << "Team: Senior Boys Team\n";
        }
    } else if (gender == "Female") {
        if (age < 18) {
            cout << "Team: Junior Girls Team\n";
        } else {
            cout << "Team: Senior Girls Team\n";
        }
    } else {
        cout << "Invalid input for gender\n";
    }

    return 0;
}

Travel Fare Calculation

Travel fare calculator scenario program image using nested if else in C++
You work for a transportation company that offers different travel options: Bus, Train, Plane, and Car. The fare depends on the type of transport and the distance traveled. The fare rules are as follows:
Bus: If the distance is more than 50 km, the fare is $15.
Train: If the distance is more than 100 km, the fare is $50.
Plane: If the distance is more than 500 km, the fare is $200.
Car: If the distance is more than 20 km, the fare is $25.
Any other transport-distance combination results in $0 fare.
Your task is to create a program that calculates the fare based on these conditions.

Test Case:
Input: Transport: Bus, Distance: 60 km
Output: Travel fare: $15
Input: Transport: Train, Distance: 150 km
Output: Travel fare: $50
Input: Transport: Car, Distance: 15 km
Output: Travel fare: $0

Explanation:

  • The program asks the user to input the type of transport (Bus, Train, Plane, or Car) and the distance traveled in kilometers.
  • Using nested if-else statements:
    • If the transport is Bus, it checks if the distance is more than 50 km. If true, it outputs the fare as $15. Otherwise, the fare is $0.
    • If the transport is Train, it checks if the distance is more than 100 km. If true, it outputs $50. Otherwise, the fare is $0.
    • If the transport is Plane, it checks if the distance is more than 500 km. If true, it outputs $200. Otherwise, the fare is $0.
    • If the transport is Car, it checks if the distance is more than 20 km. If true, it outputs $25. Otherwise, the fare is $0.
  • For any other transport type, the fare is $0 by default.
#include <iostream>
#include <string>
using namespace std;

int main() {
    string transport;
    double distance;

    cout << "Enter transport type (Bus, Train, Plane, Car): ";
    cin >> transport;
    cout << "Enter the distance traveled in km: ";
    cin >> distance;

    if (transport == "Bus") {
        if (distance > 50) {
            cout << "Travel fare: $15\n";
        } else {
            cout << "Travel fare: $0\n";
        }
    } else if (transport == "Train") {
        if (distance > 100) {
            cout << "Travel fare: $50\n";
        } else {
            cout << "Travel fare: $0\n";
        }
    } else if (transport == "Plane") {
        if (distance > 500) {
            cout << "Travel fare: $200\n";
        } else {
            cout << "Travel fare: $0\n";
        }
    } else if (transport == "Car") {
        if (distance > 20) {
            cout << "Travel fare: $25\n";
        } else {
            cout << "Travel fare: $0\n";
        }
    } else {
        cout << "Travel fare: $0\n";
    }

    return 0;
}

Fantasy Character Abilities

Characters abilities fee program using nested if else in C++
In a magical kingdom, there are adventurers. Each adventurer has a special ability that is calculated by their class and experience level. You have been assigned to create a system that can helps adventurers identify their special abilities before heading into battle:

If the class is Mage and the experience level is High, the adventurer can cast Fireball.
If the class is Warrior and the experience level is Medium, the adventurer can perform Shield Block.
If the class is Rogue and the experience level is Low, the adventurer can use Stealth.
If the class is Priest and the experience level is High, the adventurer can use Heal.
For any other class or level combination, the special ability is Unknown Ability.

Test Case:
Input: Class: Mage, Level: High
Output: Special Ability: Fireball
Input: Class: Rogue, Level: Low
Output: Special Ability: Stealth
Input: Class: Warrior, Level: High
Output: Special Ability: Unknown Ability

Explanation:

  • The program asks the user to input the adventurer’s class (Mage, Warrior, Rogue, or Priest) and their experience level (High, Medium, or Low).
  • Using nested if-else statements:
    • If the class is Mage, the program checks if the experience level is High. If true, it prints the ability as Fireball. Otherwise, it prints Unknown Ability.
    • If the class is Warrior, it checks if the experience level is Medium. If true, it prints Shield Block. Otherwise, it prints Unknown Ability.
    • If the class is Rogue, it checks if the experience level is Low. If true, it prints Stealth. Otherwise, it prints Unknown Ability.
    • If the class is Priest, it checks if the experience level is High. If true, it prints Heal. Otherwise, it prints Unknown Ability.
  • For any other class or level combination that is not explicitly mentioned, the output is Unknown Ability.
#include <iostream>
#include <string>
using namespace std;

int main() {
    string adventurerClass, experienceLevel;

    cout << "Enter class (Mage, Warrior, Rogue, Priest): ";
    cin >> adventurerClass;
    cout << "Enter experience level (High, Medium, Low): ";
    cin >> experienceLevel;

    if (adventurerClass == "Mage") {
        if (experienceLevel == "High") {
            cout << "Special Ability: Fireball\n";
        } else {
            cout << "Special Ability: Unknown Ability\n";
        }
    } else if (adventurerClass == "Warrior") {
        if (experienceLevel == "Medium") {
            cout << "Special Ability: Shield Block\n";
        } else {
            cout << "Special Ability: Unknown Ability\n";
        }
    } else if (adventurerClass == "Rogue") {
        if (experienceLevel == "Low") {
            cout << "Special Ability: Stealth\n";
        } else {
            cout << "Special Ability: Unknown Ability\n";
        }
    } else if (adventurerClass == "Priest") {
        if (experienceLevel == "High") {
            cout << "Special Ability: Heal\n";
        } else {
            cout << "Special Ability: Unknown Ability\n";
        }
    } else {
        cout << "Special Ability: Unknown Ability\n";
    }

    return 0;
}

 Magical Creature Identification

Magical creature identification scenario program image using nested if else in C++
In a mystical world, magical creatures are classified based on their habitat and diet. You are a researcher tasked with identifying these creatures:
If a creature lives in the Forest and is a Herbivore, it is classified as an Elf.
If a creature lives in a Cave and is a Carnivore, it is classified as a Troll.
If a creature lives in the Mountains and is an Omnivore, it is classified as a Giant.
If a creature lives in the Sea and is an Insectivore, it is classified as a Mermaid.
For any other habitat and diet combination, the creature is classified as an Unknown Creature.

Test Cases:
Input: Habitat: Forest, Diet: Herbivore
Output: Creature: Elf
Input: Habitat: Cave, Diet: Carnivore
Output: Creature: Troll
Input: Habitat: Desert, Diet: Herbivore
Output: Creature: Unknown Creature

Explanation:

  • The program begins by asking the user to input two key pieces of information: the creature’s habitat (such as “Forest”, “Cave”, etc.) and its diet (such as “Herbivore”, “Carnivore”, etc.). These inputs are used to determine the type of magical creature based on predefined rules.
  • Nested if-else conditions are used to evaluate the inputs step by step. This means one condition is checked inside another, allowing the program to make more specific decisions.
  • If the creature lives in a “Forest” and has a Herbivore diet, the program will output that the creature is an Elf. This is the first condition the program checks. If the habitat matches “Forest”, it will then check if the diet is “Herbivore”.
  • If the habitat is “Cave” and the creature is a Carnivore, the program outputs Troll. The program moves to this condition if the first habitat doesn’t match. Once “Cave” is found, it checks the diet for “Carnivore” to classify the creature.
  • For a creature living in “Mountains” with an Omnivore diet, the program will output Giant. The logic is similar to the previous conditions; it checks both the habitat and diet before determining the output.
  • If the creature lives in the “Sea” and has an Insectivore diet, the output will be Mermaid. Once again, the program checks for both the habitat and the specific diet to decide.
  • For any other combinations of habitat and diet that do not match these predefined pairs, the program outputs “Unknown Creature”. This is the default response when none of the specific conditions are met.
#include <iostream>
#include <string>
using namespace std;

int main() {
    string habitat, diet;

    // Input habitat and diet of the creature
    cout << "Enter the habitat of the creature (Forest, Cave, Mountains, Sea): ";
    cin >> habitat;
    cout << "Enter the diet of the creature (Herbivore, Carnivore, Omnivore, Insectivore): ";
    cin >> diet;

    // Classify the creature based on habitat and diet using nested if-else
    if (habitat == "Forest") {
        if (diet == "Herbivore") {
            cout << "Creature: Elf\n";
        } else {
            cout << "Creature: Unknown Creature\n";
        }
    } else if (habitat == "Cave") {
        if (diet == "Carnivore") {
            cout << "Creature: Troll\n";
        } else {
            cout << "Creature: Unknown Creature\n";
        }
    } else if (habitat == "Mountains") {
        if (diet == "Omnivore") {
            cout << "Creature: Giant\n";
        } else {
            cout << "Creature: Unknown Creature\n";
        }
    } else if (habitat == "Sea") {
        if (diet == "Insectivore") {
            cout << "Creature: Mermaid\n";
        } else {
            cout << "Creature: Unknown Creature\n";
        }
    } else {
        cout << "Creature: Unknown Creature\n";
    }

    return 0;
}

Travel Package Pricing

Language fee Calculator scenario program image using nested if else in C++
You work at a travel agency that offers different travel packages based on where people want to go and how long they plan to stay. The cost of the travel package depends on the destination and the length of the trip:
If someone is traveling to Europe and staying between 7 and 14 days, the cost is $1500.
If they’re going to Asia and staying between 10 and 20 days, the cost is $1200.
If they’re traveling to America and staying between 5 and 10 days, the cost is $1000.
If the destination is Africa and they’re staying between 14 and 30 days, the cost is $1800.
For any other combination of destination or duration, we don’t have a price available, and the system will show a message saying “Price not available.”
Your task is to create a program that helps people find the price of their trip based on the destination and how many days they plan to stay.

Test Cases:
Input:
Destination: Europe
Duration: 10 days
Output:
Travel Package Price: $1500
Input:
Destination: Asia
Duration: 15 days
Output:
Travel Package Price: $1200

Explanation:

  • User Input: The program starts by asking the user to input the destination (Europe, Asia, America, or Africa) and the duration of their stay in days.
  • Nested if-else Structure:
    • The outer if-else checks the destination.
    • For each destination, another if-else inside checks whether the duration falls within the specified range.
  • Conditions:
    • If the destination is Europe and the duration is between 7 and 14 days, the program outputs the price: $1500.
    • For Asia, if the duration is between 10 and 20 days, it outputs $1200.
    • For America, if the duration is between 5 and 10 days, the price is $1000.
    • For Africa, if the duration is between 14 and 30 days, the price is $1800.
  • Default Response: If the destination doesn’t match any of the four options or the duration doesn’t fall within the specified range for that destination, the output will be "Price not available".
#include <iostream>
using namespace std;

int main() {
    string destination;
    int duration;

    // Input: Asking the user for destination and duration
    cout << "Enter the destination (Europe, Asia, America, Africa): ";
    cin >> destination;
    cout << "Enter the duration of stay (in days): ";
    cin >> duration;

    // Nested if-else conditions to determine the travel package price
    if (destination == "Europe") {
        if (duration >= 7 && duration <= 14) {
            cout << "Travel Package Price: $1500\n";
        } else {
            cout << "Price not available\n";
        }
    } else if (destination == "Asia") {
        if (duration >= 10 && duration <= 20) {
            cout << "Travel Package Price: $1200\n";
        } else {
            cout << "Price not available\n";
        }
    } else if (destination == "America") {
        if (duration >= 5 && duration <= 10) {
            cout << "Travel Package Price: $1000\n";
        } else {
            cout << "Price not available\n";
        }
    } else if (destination == "Africa") {
        if (duration >= 14 && duration <= 30) {
            cout << "Travel Package Price: $1800\n";
        } else {
            cout << "Price not available\n";
        }
    } else {
        cout << "Price not available\n";
    }

    return 0;
}

Magical Artifact Quality Check

Artifact quality check program using nested if else in C++
You’re working in a magical workshop where they craft mystical artifacts. Each artifact is made from a certain material and has a specific power level. To make sure every artifact meets the right standards, you need to classify them based on these two factors:
If the artifact is made of Gold and has a High power level, it’s classified as Legendary.
If the artifact is made of Silver and has a Medium power level, it’s classified as Rare.
If the artifact is made of Bronze and has a Low power level, it’s classified as Common.
If the artifact is made of Iron and has a Medium power level, it’s classified as Uncommon.
For any other combination of material and power level, the artifact is classified as Unknown Quality.
Your job is to write a program that will classify the artifacts based on these rules.

Test Cases:
Input:
Material: Gold
Power Level: High
Output:
Classification: Legendary
Input:
Material: Silver
Power Level: Medium
Output:
Classification: Rare

Explanation:

  • User Input: The program starts by asking for the material and power level of the artifact.
  • Nested if-else Structure:
    • The outer if-else checks the material.
    • For each material, another if-else checks the power level.
  • Conditions:
    • If the material is Gold and the power level is High, it outputs “Legendary”.
    • For Silver and Medium, it outputs “Rare”.
    • For Bronze and Low, it outputs “Common”.
    • For Iron and Medium, it outputs “Uncommon”.
  • Default Response: If the material or power level doesn’t match any of the specified conditions, the output will be “Unknown Quality”.
#include <iostream>
using namespace std;

int main() {
    string material;
    string powerLevel;

    // Input: Asking the user for material and power level
    cout << "Enter the material of the artifact (Gold, Silver, Bronze, Iron): ";
    cin >> material;
    cout << "Enter the power level of the artifact (High, Medium, Low): ";
    cin >> powerLevel;

    // Nested if-else conditions to determine the classification
    if (material == "Gold") {
        if (powerLevel == "High") {
            cout << "Classification: Legendary\n";
        } else {
            cout << "Classification: Unknown Quality\n";
        }
    } else if (material == "Silver") {
        if (powerLevel == "Medium") {
            cout << "Classification: Rare\n";
        } else {
            cout << "Classification: Unknown Quality\n";
        }
    } else if (material == "Bronze") {
        if (powerLevel == "Low") {
            cout << "Classification: Common\n";
        } else {
            cout << "Classification: Unknown Quality\n";
        }
    } else if (material == "Iron") {
        if (powerLevel == "Medium") {
            cout << "Classification: Uncommon\n";
        } else {
            cout << "Classification: Unknown Quality\n";
        }
    } else {
        cout << "Classification: Unknown Quality\n";
    }

    return 0;
}

Adventure Gear Pricing

Adventure gear calculator scenario program in C++ using nested if-else statements
You are managing a store that sells adventure gear to adventurers gearing up for their next quest. Each type of gear has a specific pricing structure based on the quantity ordered. Here’s how the pricing works:
If you order a Sword and the quantity is between 3 and 7, the total price is calculated as quantity * 100 + 50.
If you order a Shield and the quantity is between 2 and 5, the total price is calculated as quantity * 80 + 30.
If you order a Helmet and the quantity is between 4 and 8, the total price is calculated as quantity * 60 + 20.
If you order a pair of Boots and the quantity is between 1 and 3, the total price is calculated as quantity * 40 + 10.
For any other gear type or quantity outside these ranges, the price will be shown as “Price not available”.
You need to write a program to calculate the total price based on the type of gear and the quantity ordered.

Test Cases:
Input:
Gear: Sword
Quantity: 5
Output:
Total Price: $550
Input:
Gear: Boots
Quantity: 2
Output:
Total Price: $90

Explanation:

  • User Input: The program starts by asking for the type of gear and the quantity ordered.
  • Nested if-else Structure:
    • The outer if-else checks the gear type.
    • For each gear type, another if-else checks if the quantity is within the allowed range.
  • Conditions:
    • For Swords (3 to 7 units), the price is calculated as quantity * 100 + 50.
    • For Shields (2 to 5 units), the price is calculated as quantity * 80 + 30.
    • For Helmets (4 to 8 units), the price is calculated as quantity * 60 + 20.
    • For Boots (1 to 3 units), the price is calculated as quantity * 40 + 10.
  • Default Response: If the gear type or quantity doesn’t match any of the specified conditions, the output will be “Price not available”.
#include <iostream>
using namespace std;

int main() {
    string gear;
    int quantity;
    
    // Input: Asking the user for gear type and quantity
    cout << "Enter the type of gear (Sword, Shield, Helmet, Boots): ";
    cin >> gear;
    cout << "Enter the quantity: ";
    cin >> quantity;
    
    // Nested if-else conditions to determine the price
    if (gear == "Sword") {
        if (quantity >= 3 && quantity <= 7) {
            int price = quantity * 100 + 50;
            cout << "Total Price: $" << price << endl;
        } else {
            cout << "Price not available\n";
        }
    } else if (gear == "Shield") {
        if (quantity >= 2 && quantity <= 5) {
            int price = quantity * 80 + 30;
            cout << "Total Price: $" << price << endl;
        } else {
            cout << "Price not available\n";
        }
    } else if (gear == "Helmet") {
        if (quantity >= 4 && quantity <= 8) {
            int price = quantity * 60 + 20;
            cout << "Total Price: $" << price << endl;
        } else {
            cout << "Price not available\n";
        }
    } else if (gear == "Boots") {
        if (quantity >= 1 && quantity <= 3) {
            int price = quantity * 40 + 10;
            cout << "Total Price: $" << price << endl;
        } else {
            cout << "Price not available\n";
        }
    } else {
        cout << "Price not available\n";
    }

    return 0;
}

At SyntaxScenarios, we make coding fun and interesting by crafting real-world scenario based coding questions with engaging visuals. By solving these nested if-else problems, you’ve strengthened your ability to think logically and handle complex decision-making in code. Remember, coding is all about breaking down problems and finding the right path through conditions—skills that will serve you well in any programming journey. Keep practicing, stay curious, and enjoy the satisfaction of solving each new puzzle that comes your way!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top