title: Having a divide by zero in my code
body: <p>Hes my code and I can't figure out where I'm getting the divide by zero problem.</p>
  
  <p><strong>mreviewApp.cpp</strong></p>
  
  <pre><code>const int SIZE = 80;
  const char DELIMIT = '|';
  
  void parseLine(const char line[], string&amp; title, int&amp; rating);
  void stringTrim(char st[]);
  void printMrList(std::vector &lt;Mreview&gt; mrList);
  Mreview searchTitle(std::vector &lt;Mreview&gt; &amp;mrList, string title);
  
  
  int main()
   {
    ifstream fin;
  
    fin.open("rating_list.txt");
    if (fin.fail()) {
      cerr &lt;&lt; "Input file opening error.\n";
      exit(1);
    }
  
    char line[SIZE];
    string title;
    int rating;
    int lineCount = 0;
  
    std::vector &lt;Mreview&gt; mrList;
  
    /* Process one line at a time */
    // Read the first line
    fin.getline(line, SIZE);
    stringTrim(line);
  
    // Process loop
    while (strlen(line) != 0) { 
      parseLine(line, title, rating);
      lineCount++;
  
      Mreview review = searchTitle(mrList, title);
      review.addScore(rating);
  
      // Read the next line
      fin.getline(line, SIZE);
      stringTrim(line);
    }
  
    cout &lt;&lt; "** PROCESS DONE. There were " &lt;&lt; mrList.size() &lt;&lt; " movie titles. **\n\n";
  
    printMrList(mrList);
    // Close the input file before exit.
    fin.close();
  
    system("Pause");
    return 0;
  }
  
  void parseLine(const char line[], string&amp; title, int&amp; rating)
  {
    char s[SIZE], r[SIZE];
    const char *ptr, *temp1;
    char *temp2;
  
    ptr = strchr(line, DELIMIT);
  
    if (ptr != NULL) {
      // First grab the title string (until '|').
      temp1 = line;
      temp2 = s;
      while (temp1 != ptr)
        *temp2++ = *temp1++;
  
      *temp2 = '\0';
  
      stringTrim(s);
      title = s;
  
      // Second grab the rating number
      temp1 = ptr+1;
      temp2 = r;
      while (*temp1 != '\0')
        *temp2++ = *temp1++;
  
      *temp2 = '\0';
  
      stringTrim(r);
      rating = atoi(r);
    }
    else {
      title = "";
      rating = 0;
    }
  }
  
  void stringTrim(char st[])
  {
    char* ptr;
  
    for (ptr = st; *ptr; ptr++) ;
    for (ptr--; *ptr == ' ' &amp;&amp; ptr &gt;= st; ptr--) ;
    ptr++;
    *ptr = '\0';
  
    for (ptr = st; *ptr &amp;&amp; *ptr == ' '; ptr++) ;
  
    if (*ptr &amp;&amp; ptr != st) {
      char* ptr2;
      for (ptr2 = st; *ptr; *ptr2++ = *ptr++) ;
      *ptr2 = '\0';
    }
  }
  
  void printMrList(std::vector &lt;Mreview&gt; mrList)
  {
      std::vector&lt;Mreview&gt;::iterator itr;
      for(itr = mrList.begin(); itr != mrList.end(); itr++) {
          Mreview review = *(itr);
          cout &lt;&lt; review.getTitle() &lt;&lt; "\t\t" &lt;&lt; review.getTotalScore() &lt;&lt; "\t\t" &lt;&lt; review.aveRating() &lt;&lt; endl;
      }
  }
  
  Mreview searchTitle(std::vector &lt;Mreview&gt; &amp;mrList, string title)
  {
      Mreview review (title); 
      std::vector&lt;Mreview&gt;::iterator itr;
      for(itr = mrList.begin(); itr != mrList.end(); itr++) {
          Mreview r2d2 = *(itr);
          if(review.getTitle() == r2d2.getTitle())
              return r2d2;
      }
      mrList.push_back(review);
      return review;
  }
  </code></pre>
  
  <p><strong>mreview.cpp</strong></p>
  
  <pre><code>Mreview::Mreview(string ttl)
    : title(ttl), totalScore(0), numRatings(0) {}
  
  Mreview::Mreview(string ttl, int score)
    : title(ttl), totalScore(score), numRatings(1) {}
  void Mreview::addScore(int score)
  {
      this-&gt;totalScore += score;
      this-&gt;numRatings += 1;
  }
  
  double Mreview::aveRating() const
  {
      double rating = totalScore/numRatings;
      return rating;
  }
  </code></pre>
  
  <p><strong>mreview.h</strong></p>
  
  <pre><code>#ifndef MREVIEW_H
  #define MREVIEW_H
  
  #include &lt;string&gt;
  using namespace std;
  
  class Mreview
  {
  public:
    Mreview(string ttl = "N/A");
    Mreview(string ttl, int firstScore);
  
    string getTitle() const { return title; }
    int getTotalScore() const { return totalScore; }
    int getNumRatings() const { return numRatings; }
  
    void addScore(int score);
    double aveRating() const;
  
  private:
    string title;
    int totalScore;
    int numRatings;
  };
  
  #endif
  </code></pre>
  
  <p>My problem is that I am unable to figure out what I have to do to fix the problem. I have read the comments and I am still confused.</p>