Enumerations and User Input
<p>I was wondering if enumeration is commonly used with user input. I'm doing an exercise in which in my Book class I have to create an enum Genre with different genre enumerators such as fiction, non, fiction etc. </p>

<p>When the user uses the program, he/she is asked for certain information about the book being stored. For a genre, normally I would just do this with a string function and restrict it to certain names with if statements. </p>

<p>However, I'm not sure how to accomplish the same process with an enumerated type, nor do I know if it's even supposed to be used for that sort of thing. Here is the code if you're interested.</p>

<pre><code>#include "std_lib_facilities.h"

//Classes-----------------------------------------------------------------------

class Book{
public:
       Book(){}; // default constructor
       //operators
       friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const Book&amp; val);
       bool Book::operator==(const Book&amp; check)
       //enumerators
       enum Genre{
            fiction, nonfiction, periodical, biography, children};
       //member functions
       string title();
       string author();
       int copyright();
       void ISBN();
       bool checkout();
private:
        string title_;
        string author_;
        int copyright_;
        int ISBN1;
        int ISBN2;
        int ISBN3;
        char ISBN4;
        bool checkout_;
};

// Error Function---------------------------------------------------------------

void _error(const string&amp; s)
{
     cout &lt;&lt; endl;
     cout &lt;&lt; "Error: " &lt;&lt; s &lt;&lt; endl;
     cout &lt;&lt; endl;
}

// Member Functions-------------------------------------------------------------

string Book::title()
{
       cout &lt;&lt; "Title: ";
       getline(cin,title_);
       cout &lt;&lt; endl;
       return title_;
}

string Book::author()
{
       cout &lt;&lt; "Author: ";
       getline(cin,author_);
       cout &lt;&lt; endl;
       return author_;
}

int Book::copyright()
{
    cout &lt;&lt; "Copyright: ";
    cin &gt;&gt; copyright_;
    cout &lt;&lt; endl;
    return copyright_;
}

void Book::ISBN()
{
     cout &lt;&lt; "ISBN (Use spaces): ";
     cin &gt;&gt; ISBN1 &gt;&gt; ISBN2 &gt;&gt; ISBN3 &gt;&gt; ISBN4;
     if((ISBN1&lt;0) || (ISBN2&lt;0) || (ISBN3&lt;0) || (ISBN1&gt;9) || (ISBN2&gt;9) || (ISBN3)&gt;9)
               _error("Must be single digit.");
     else if(!isdigit(ISBN4) &amp;&amp; !isalpha(ISBN4))
               _error("Must be single digit or letter.");
     else{ cout &lt;&lt; endl;
           return;}
}

bool Book::checkout()
{
     char check;
     cout &lt;&lt; "Checked out?(Y or N): ";
     cin &gt;&gt; check;
     switch(check){
     case 'Y':
          cout &lt;&lt; endl;
          return true;
          break;
     case 'N':
          cout &lt;&lt; endl;
          return false;
          break;
     default: 
              _error("Must be Y or N.");}
}

// Operator Overloads-----------------------------------------------------------

ostream&amp; operator&lt;&lt;(ostream&amp; out, const Book&amp; val){
         out &lt;&lt; "Title: " &lt;&lt; val.title_ &lt;&lt; endl;
         out &lt;&lt; "Author: " &lt;&lt; val.author_ &lt;&lt; endl;
         out &lt;&lt; "ISBN: " &lt;&lt; val.ISBN1 &lt;&lt; "-" &lt;&lt; val.ISBN2 &lt;&lt; "-" &lt;&lt; val.ISBN3 &lt;&lt; "-" &lt;&lt; val.ISBN4 &lt;&lt; endl;
         out &lt;&lt; endl;
         return out;}

bool Book::operator==(const Book&amp; check){
     return((ISBN1 == check.ISBN1) &amp;&amp; (ISBN2 == check.ISBN2) &amp;&amp; (ISBN3 == check.ISBN3)
             &amp;&amp; (ISBN4 == check.ISBN4));}

// Main-------------------------------------------------------------------------   

int main()
{
    bool finished = false;
    char notfinished;
    while(!finished)
    {
      Book book;
      book.title();
      book.author();
      book.copyright();
      book.ISBN();
      book.checkout();
      cout &lt;&lt; "Do you wish to store another book?(Y or N): ";
      cin &gt;&gt; notfinished;
      if(notfinished == 'Y'){ 
                     cin.ignore();
                     cout &lt;&lt; endl;}
      else if(notfinished == 'N') finished = true;
      else _error("Must be Y or N");
      }
     keep_window_open();
     }
</code></pre>

<p>Note that some things aren't being used at the moment because the feature they are a part of hasn't been fully implemented yet (storing in a library, outputting books, etc.)   </p>

<p>So what would it take to accept user input for the enumerators listed, if even possible? I was thinking something along the lines of making a Genre variable. Then having a function where the user inputs for cin>>variable. However, I'm guessing that the function wouldn't understand an input like 'fiction' and would only accept the enumerator values and input.      </p>
