title: Searching parallel arrays
body: <p>My program is designed to take input from a file containing a list of titles and authors. The file looks like so:</p>
  
  <pre>
  title
  associated author
  next title
  associated author
  etc.
  </pre>
  
  <p>The problem I'm having is with my showBooksByTitle and showBooksByAuthor functions. Right now this code returns only exact matches and also prints an empty newline and a new line with some spaces and a ().</p>
  
  <p>Of course any help is greatly appreciated. This is my first year programming. I've included the whole code just to be safe that I'm not leaving out anything that could be the problem.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;fstream&gt;
  #include&lt;cstring&gt;
  
  using namespace std;
  
  struct Book {
      string title;
      string author;
  };
  
  const int ARRAY_SIZE = 1000;
  Book books [ARRAY_SIZE];
  
  int loadData (string);
  void showAll (int);
  int showBooksByAuthor (int, string);
  int showBooksByTitle (int, string);
  
  int main() {
      //Declare variables
      string pathname;
      string title;
      string name;
      string word;
      int count;
      char response;
  
      //ask user for pathname
      cout &lt;&lt; "What is the path of the library file? ";
      cin &gt;&gt; pathname;
      cout &lt;&lt; endl;
      count = loadData(pathname);
  
      //input data into arrays
      loadData(pathname);
      cout &lt;&lt; endl &lt;&lt; count &lt;&lt; " records loaded successfully." &lt;&lt; endl &lt;&lt; endl;
  
      //Show user menu
      cout &lt;&lt; "Please enter Q to Quit, A to search for the Author, T to search for the Title, "
      &lt;&lt; endl &lt;&lt; "or S to Show all: ";
      cin &gt;&gt; response;
  
      switch(response) {
          case 'q':
              break;
          case 'Q':
              break;
          case 'a':
              cout &lt;&lt; endl &lt;&lt; "Please enter author's name: ";
              cin &gt;&gt; name;
              showBooksByAuthor(count, name);
              break;
          case 'A':
              cout &lt;&lt; endl &lt;&lt; "Please enter author's name: ";
              cin &gt;&gt; name;
              showBooksByAuthor(count, name);
              break;
          case 't':
              cout &lt;&lt; endl &lt;&lt; "Please enter all or part of the title: ";
              cin &gt;&gt; title;
              showBooksByTitle(count, title);
              break;
          case 'T':
              cout &lt;&lt; endl &lt;&lt; "Please enter all or part of the title: ";
              cin &gt;&gt; title;
              showBooksByTitle(count, title);
              break;
          case 's':
              cout &lt;&lt; endl;
              showAll(count);
              break;
          case 'S':
              cout &lt;&lt; endl;
              showAll(count);
              break;
          default:
              cout &lt;&lt; endl &lt;&lt; "Invaled input, please try again: ";
              break;
      }
  
      //pause and exit
      cout &lt;&lt; endl;
      system("PAUSE");
      return 0;
  }
  
  
  int loadData(string pathname) {
      int i = 0;
      int j = 0;
      ifstream library;
  
      //open file, if not successful, output error message
      library.open(pathname.c_str());
      if (!library.is_open()) {
          cout &lt;&lt; "Unable to open input file." &lt;&lt; endl;
          return -1;
      }
      //reads title and author from file into designated string
      //this is assuming title comes first and author comes after
      while(!library.eof()) {
          getline(library, books[i].title);
          getline(library, books[i].author);
          i++;
      }
      return i;
  }
  
  void showAll (int count) {
      for (int i = 0; i &lt; count; i++) {
          cout &lt;&lt; books[i].title &lt;&lt; " (" &lt;&lt; books[i].author &lt;&lt; ")" &lt;&lt; endl;
      }
  }
  
  int showBooksByAuthor(int count, string name) {
      int found;
      for(int n = 0; n &lt; 28; n++) {
          found = name.find(books[n].author);
          if(found != string::npos) {
              cout &lt;&lt; endl &lt;&lt; books[n].title &lt;&lt; " (" &lt;&lt; books[n].author &lt;&lt; ")" &lt;&lt; endl;
          }
      }
      return 0;
  }
  
  
  int showBooksByTitle (int count, string title) {
      int found;
      for(int n = 0; n &lt; 28; n++) {
          found = title.find(books[n].title);
          if(found !=string::npos) {
              cout &lt;&lt; endl &lt;&lt; books[n].title &lt;&lt; " (" &lt;&lt; books[n].author &lt;&lt; ")" &lt;&lt; endl;
          }
      }
      return 0;
  }
  </code></pre>