0
0
Cprogramming~15 mins

If statement in C - Mini Project: Build & Apply

Choose your learning style9 modes available
If Statement Basics in C
📖 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 C program that uses an if statement to check a person's age and print whether they can vote or not.
📋 What You'll Learn
Create an integer variable called age with the value 20
Create an integer variable called voting_age with the value 18
Use an if statement to check if age is greater than or equal to voting_age
Print "You can vote!" if the condition is true
Print "You cannot vote yet." if the condition is false
💡 Why This Matters
🌍 Real World
Checking age eligibility is common in many real-world applications like voting, driving, or buying age-restricted products.
💼 Career
Understanding if statements is fundamental for any programming job because it helps make decisions in code.
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
Create the voting age variable
Create an integer variable called voting_age and set it to 18.
C
Need a hint?

Use int voting_age = 18; inside the main function after age.

3
Write the if statement to check voting eligibility
Use an if statement to check if age is greater than or equal to voting_age. Inside the if block, write printf("You can vote!\n");. Use an else block to print "You cannot vote yet.\n".
C
Need a hint?

Use if (age >= voting_age) and else with printf statements inside each block.

4
Print the result
Run the program and print the output. Use printf statements inside the if and else blocks as before. The program should print You can vote!.
C
Need a hint?

Compile and run the program to see the output.