Question

how to check enums in C let us say I have the following enum: enum days{...

how to check enums in C

let us say I have the following enum:

enum days{

MONDAY,

SUNDAY,

THURSDAY

} ;

I want to check if a struct that contains this enum has a valid value for example

typedef struct {

int date;

enum day name;

} complete_date;

so now I want to check if a complete_date has a valid enum

it can only be valid if it is MONDAY,SUNDAY, OR THURSDAY.

i want to assert that becuase if it has let us say TUESDAY i want to end the program;

i hope you can understand what I am trying to do.

this is a c programming question.

Thnaks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

So if the complete_date.day_name value is 0,1 or 2 then it is valid. For example the below program would illusrate it.

#include<stdio.h>

enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};

int main()

{

    enum week day;

    day = Wed;

    printf("%d",day);

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
how to check enums in C let us say I have the following enum: enum days{...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my program in C. I should be able to print out Monday, Tuesday and...

    This is my program in C. I should be able to print out Monday, Tuesday and Wednesday. However, I am not sure what I am doing wrong. Please tell me. So far I get these errors: warning: ‘enum day’ declared inside parameter list will not be visible outside of this definition or declaration const char* DayToString(enum color x)// I guess this is just a warning, nothing wrong error: parameter 1 (‘x’) has incomplete type const char* DayToString(enum color x) //I...

  • I need to complete the C++ program for hotel reservation. In the main cpp you have...

    I need to complete the C++ program for hotel reservation. In the main cpp you have to display the hotel information from the hotel.txt based on customer preferences(which can be taken from the User.txt) For example, if the customer's budget is 200$, then only the hotels with prices below that amount should be displayed. Then the user has an option to choose which one to reserve for the particular time(which also can be found in the user.txt) The last two...

  • My question is about the case study “ Comparing Apples and Oranges: which group yuelds the...

    My question is about the case study “ Comparing Apples and Oranges: which group yuelds the best profit?” 1) Using the Excel apreadsheet attached to complete the rooms sold and revenue projections based on the above case study. Case Study: "Comparing Apples and Oranges: Which Group Yields the Best Profit?" ​The Diamond Peak Hotel, one of 45 hotels in the Host Marriott management company, was bustling with business this Thursday afternoon as the hour of the daily revenue meeting drew...

  • C++. Need some help getting started. We will also have the following two functions: 1. A...

    C++. Need some help getting started. We will also have the following two functions: 1. A mutate function that randomly modifies a chromosome. 2. A crossover function that takes two chromosomes and splits each one at the same spot, then combines them together. Our genetic algorithm works by iterating over generations of chromosomes via the following process: 1. Generate random population. 2. Until we get an answer that is good enough, do the next steps in a loop: (a) Do...

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective...

    SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective To gain experience with the operations involving binary search trees. This data structure as linked list uses dynamic memory allocation to grow as the size of the data set grows. Unlike linked lists, a binary search tree is very fast to insert, delete and search. Project Description When an author produce an index for his or her book, the first step in this process...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT