title: Cannot acquire correct fractional values in output
body: <p>I believe I've corrected most of the program.  So far it's error-free, but I'm receiving odd values during a certain portion of execution:</p>
  
  <p>My output is:</p>
  
  <blockquote>
  <pre><code>0/2
  3/4
  Cannot divide by zero
  Cannot divide by zero
  0
  0
  Cannot divide by zero
  ____________________________________
  </code></pre>
  </blockquote>
  
  <p>I know that my calculations in my functions are correct, but I believe they are not receiving the saved values for the variables being passed to them.</p>
  
  <p>Here is my class:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  class fraction {
  private:
      long num, den;
  
  public:
      fraction() {}
      fraction(int n, int d) {
          num = n;
          if (d == 0) {
              cout &lt;&lt; "Careful there, Tim..." &lt;&lt; endl;
              exit(0);
          } else
              den = d;
      }
  
      void setNum(long l_num) { num = l_num; }
      void setDen(long l_den) { den = l_den; }
      long getNum() { return num; }
      long getDen() { return den; }
  
      long add(fraction&amp; a, fraction&amp; b) {
          int n = (a.getNum() * b.getDen()) + (b.getNum() * a.getDen());
          int d = a.getNum() * b.getDen();
          num = n / gcd(n, d);
          den = d / gcd(n, d);
          return num;
          return den;
      }
  
      long sub(fraction&amp; a, fraction&amp; b) {
          int n = a.getNum() * b.getDen() - b.getNum() * a.getDen();
          int d = a.getNum() * b.getDen();
          num = n / gcd(n, d);
          den = d / gcd(n, d);
      }
  
      long mult(fraction&amp; a, fraction&amp; b) {
          int n = a.getNum() * b.getNum();
          int d = a.getDen() * b.getDen();
          num = n / gcd(n, d);
          den = d / gcd(n, d);
      }
  
      long div(fraction&amp; a, fraction&amp; b) {
          int n = a.getNum() * b.getDen();
          int d = a.getDen() * b.getNum();
          num = n / gcd(n, d);
          den = d / gcd(n, d);
      }
  
      long inc(fraction&amp; a) {
          int n = a.getNum() + 1;
          int d = a.getDen() + 1;
      }
  
      long gcd(long n, long d) {
          int remainder;
          while (d != 0) {
              remainder = n % d;
              n = d;
              d = remainder;
          }
          return n;
      }
      void print() // Display method
      {
          if (den == 1)
              cout &lt;&lt; num &lt;&lt; endl;
          else if (den == 0)
              cout &lt;&lt; "Cannot divide by zero" &lt;&lt; endl;
          else
              cout &lt;&lt; num &lt;&lt; "/" &lt;&lt; den &lt;&lt; endl;
      }
  };
  </code></pre>
  
  <p>My instructor gave us strict instructions to NOT modify his given <code>int main()</code>, but here it is:</p>
  
  <pre><code>int main() { // define seven instances of the class fraction
      fraction f1, f2, f3, f4, f5, f6, f7;
      // set values for the numerator and denominator to f1 and print
      // them
      f1.setDen(2L);
      f1.setNum(0L);
      f1.print();
  
      // set values for the numerator and denominator to f2 and print them
      f2.setDen(4L);
      f2.setNum(3L);
      f2.print();
      f3.add(f1, f2);
      f3.print();
      f4.sub(f1, f2);
      f4.print();
      f5.mult(f1, f2);
      f5.print();
      f6.div(f1, f2);
      f6.print();
      f7.inc(f1);
      f7.print();
  }
  </code></pre>
  
  <p>I've already requested help on this program once before from SO, and I was approached with very nice people.  I've e-mailed my professor twice more, and called his office.  He has not answered // read my e-mails <em>read cc on open</em> and has not answered the voicemail I've left.</p>