0
0
Cprogramming~15 mins

Enum usage in C - Mini Project: Build & Apply

Choose your learning style9 modes available
Enum usage
📖 Scenario: You are creating a simple program to represent the days of the week using an enum. This helps to give meaningful names to numbers, making your code easier to read and understand.
🎯 Goal: Build a program that defines an enum for the days of the week, assigns a day to a variable, and prints the numeric value of that day.
📋 What You'll Learn
Define an enum named Day with days from Monday to Sunday
Create a variable of type Day and assign it the value Wednesday
Print the numeric value of the assigned day using printf
💡 Why This Matters
🌍 Real World
Enums are used in programs to give meaningful names to sets of related values, like days, states, or options, making code easier to read and maintain.
💼 Career
Understanding enums is important for writing clear and maintainable code in many programming jobs, especially in systems programming, embedded systems, and application development.
Progress0 / 4 steps
1
Define the enum for days of the week
Write an enum named Day with these exact members: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday.
C
Need a hint?

Use the enum keyword followed by the name Day and list the days inside curly braces separated by commas.

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

Use the syntax enum Day today = Wednesday; to declare and assign the variable.

3
Print the numeric value of the day
Use printf to print the numeric value of the variable today. Use the format specifier %d.
C
Need a hint?

Wrap your code inside int main() and use printf("%d\n", today); to print the value.

4
Run the program to display the day number
Complete the program by adding the main function if not already present, and run it to display the numeric value of today. The output should be 2.
C
Need a hint?

Make sure your main function prints the value of today and returns 0.