0
0
Cprogramming~15 mins

Nested conditional statements - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Statements
📖 Scenario: You are creating a simple program to check a person's age and determine their life stage. This is like asking a friend, "Are you a child, a teenager, or an adult?" based on their age.
🎯 Goal: Build a C program that uses nested if statements to decide if a person is a child, teenager, or adult based on their age.
📋 What You'll Learn
Create an integer variable called age with the value 15.
Create an integer variable called child_age_limit and set it to 12.
Use nested if statements to check if age is less than or equal to child_age_limit, then print "Child".
If not a child, check if age is less than or equal to 19, then print "Teenager".
If neither child nor teenager, print "Adult".
Print the result using printf.
💡 Why This Matters
🌍 Real World
Nested conditions help computers make decisions step-by-step, like deciding what message to show based on age.
💼 Career
Understanding nested conditionals is important for writing clear and correct decision-making code in many programming jobs.
Progress0 / 4 steps
1
Create the age variable
Create an integer variable called age and set it to 15.
C
Need a hint?

Use int age = 15; inside the main function.

2
Add the child_age_limit variable
Create an integer variable called child_age_limit and set it to 12.
C
Need a hint?

Declare int child_age_limit = 12; after age.

3
Write nested if statements to check age
Use nested if statements to check if age is less than or equal to child_age_limit, then print "Child". Otherwise, check if age is less than or equal to 19, then print "Teenager". If neither, print "Adult".
C
Need a hint?

Use if inside else to create nested conditions.

4
Print the result
Make sure the program prints the correct life stage based on the age variable using printf. Run the program to see the output.
C
Need a hint?

Run the program and check the output is exactly "Teenager" followed by a new line.