0
0
Cprogramming~15 mins

If–else statement in C - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else statement
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Build a program that uses an if-else statement to decide if a person can vote based on their age.
📋 What You'll Learn
Create an integer variable called age with the value 20
Create an integer variable called voting_age and set it to 18
Use an if-else statement to check if age is greater than or equal to voting_age
Print "You are eligible to vote." if the condition is true
Print "You are not eligible to vote." if the condition is false
💡 Why This Matters
🌍 Real World
Checking age eligibility is common in many real-life situations like voting, driving, or drinking alcohol.
💼 Career
Understanding if-else statements is essential for any programming job because it helps programs make decisions.
Progress0 / 4 steps
1
Create the age variable
Create an integer variable called age and set it to 20.
C
Need a hint?

Use int age = 20; inside the main function.

2
Add the voting age variable
Create an integer variable called voting_age and set it to 18.
C
Need a hint?

Declare int voting_age = 18; after age.

3
Write the if-else statement
Use an if-else statement to check if age is greater than or equal to voting_age. Inside the if, write a comment // Eligible. Inside the else, write a comment // Not eligible.
C
Need a hint?

Use if (age >= voting_age) {} and else {} blocks with comments inside.

4
Print the eligibility message
Inside the if block, write printf("You are eligible to vote.\n");. Inside the else block, write printf("You are not eligible to vote.\n");. Then run the program to see the output.
C
Need a hint?

Use printf inside each block to show the correct message.