0
0
Cprogramming~15 mins

Else–if ladder in C - Mini Project: Build & Apply

Choose your learning style9 modes available
Else-if ladder
📖 Scenario: You are creating a simple program that categorizes a person's age group based on their age.
🎯 Goal: Build a program that uses an else-if ladder to print the correct age group for a given age.
📋 What You'll Learn
Create an integer variable called age with the value 25
Create an else-if ladder to check the age and assign the correct age group
Use these age groups: Child (0-12), Teen (13-19), Adult (20-59), Senior (60 and above)
Print the age group using printf
💡 Why This Matters
🌍 Real World
Programs often need to make decisions based on ranges, like categorizing ages, prices, or scores.
💼 Career
Understanding <code>else-if</code> ladders is essential for writing clear decision-making code in many software jobs.
Progress0 / 4 steps
1
Create the age variable
Create an integer variable called age and set it to 25.
C
Need a hint?

Use int age = 25; inside the main function.

2
Set up the else-if ladder
Add an else-if ladder to check the value of age for these groups: age <= 12, age <= 19, age <= 59, and else for 60 and above.
C
Need a hint?

Use if, else if, and else to check the age ranges.

3
Add printf statements for each age group
Inside each block of the else-if ladder, add a printf statement to print the correct age group: "Child", "Teen", "Adult", or "Senior".
C
Need a hint?

Use printf inside each condition to print the age group.

4
Print the age group
Run the program and print the age group for age = 25 using printf. The output should be Adult.
C
Need a hint?

Run the program and check the output is Adult.