Explore BrainMass

A C program that uses enumerated types

This content was STOLEN from BrainMass.com - View the original, and get the solution, here!

Create a set/list of enumerated constants called week that contains the days of the week. Have a variable called today that is of type week. Assign a value to today. If the day is Monday through Friday, print "Go to work!" If the day is Saturday or Sunday, print "You can rest today!"

© BrainMass Inc. brainmass.com September 19, 2018, 2:59 am ad1c9bdddf - https://brainmass.com/physics/ac/a-c-program-that-uses-enumerated-types-166088

Solution Preview

The point of using an enumeration type is that you can provide symbolic names for values that are related. The example of days of the week is a good one. We define an enum using the following statement:

enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};

This provides us with an enum that is available for us to use for other variable declarations. So we can create a variable "today" like this:

enum week today;

Now it is possible to assign the value "Monday" to this variable:

today = Monday;

Notice that we're not using " around the name Monday. That's ...

Solution Summary

In this solution I provide a simple and easy to understand C program that uses an enumerated type to represent the days of the week. The program reads input from the user and prints a different message depending on which day of the week was entered.