I have an enum declaration as:
enum qty { cars = 10, bikes = 9, horses = 9 ... } // total 28
How could I add up all the associated values of enumerator-list?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t know at runtime the contents of an
enumin C.Besides, this sounds like a misuse of enumerations. You should use them to define constants that you will use inside your code, not to store quantities or stuff like that which should otherwise be variable: enumeration values are immutable. Use integer arrays for that purpose; you can loop through these.