0
0
Cprogramming~15 mins

Enum declaration - Mini Project: Build & Apply

Choose your learning style9 modes available
Enum declaration
📖 Scenario: You are creating a simple program to represent days of the week using an enum. This helps you use meaningful names instead of numbers in your code.
🎯 Goal: Learn how to declare an enum in C to represent the days of the week and print one of the days.
📋 What You'll Learn
Declare an enum named Day with the days: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.
Create a variable of type Day and assign it the value Wednesday.
Print the integer value of the Day variable.
💡 Why This Matters
🌍 Real World
Enums help represent fixed sets of related values like days, colors, or states in a readable way.
💼 Career
Understanding enums is important for writing clear and maintainable code in C programming jobs.
Progress0 / 4 steps
1
Declare the enum Day
Declare an enum named Day with these exact members in order: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.
C
Need a hint?

Use the syntax enum Name { item1, item2, ... }; to declare an enum.

2
Create a variable of type Day
Create a variable named today of type Day and assign it the value Wednesday.
C
Need a hint?

Use enum Day variableName = Value; to create and assign an enum variable.

3
Print the integer value of today
Write a printf statement to print the integer value of the variable today.
C
Need a hint?

Use printf("%d\n", variable); to print an integer value.

4
Run the program to see the output
Run the program and observe the output. It should print the integer value corresponding to Wednesday.
C
Need a hint?

The output should be 3 because Sunday starts at 0 and Wednesday is the fourth item.