COSC-051 Lecture Notes - Lecture 7: Fruit Snack, Semicolon, Infinite Loop
Document Summary
Use user input as intexpression in switch statement. Use menu choices as exp values to test against in the case statements. Ex: switch (gender) break; break; case f" : cout << female ; case m": cout << male ; default: cout << invalid gender ; A data type created by the programmer. Contains a set of named integer constants. Format: enum name {val1, val2, , van}; Examples: enum fruit {apple, grape, orange}; enum days {mon, tue, wed, thur, fri}; To define variables, use the enumerated data type name. A variable may contain any valid value for the data type snack = orange; if (workday == wed) // none here. Enum data type values are associated with integers, starting at 0 enum fruit {apple, grape, orange}; Enumerated data type values can be compared using their integer values if (snack ==1) Enumerated data type values cannot be assigned using their integer values snack = 2; // won"t work".