Enumeration Basics | C++

February 27th, 2021 11:40:39 PM

#include <iostream> using namespace std; /* Description: uses switch case statements to determine whether it is hot or not outside. Also uses toupper() function which forces user input char to be uppercase in order to work for the switch statement */ int main() { char choice; cout << "S = Summer, F = Fall, W = Winter, P = Spring" << endl; cout << "Enter a character to represent a season: ";asdasdasdasd cin >> choice; enum Season {SUMMER='S', FALL='F', WINTER='W', SPRING='P'}; switch(toupper(choice)) // This switch statement compares a character entered with values stored inside of an enum { case SUMMER: cout << "It's very hot outside." << endl; break; case FALL: cout << "It's great weather outside." << endl; break; case WINTER: cout << "It's fairly cold outside." << endl; break; case SPRING: cout << "It's rather warm outside." << endl; break; default: cout << "Wrong choice" << endl; break; } return 0; }

Featured Posts