title: Adding fractions using classes (Wrong output)
body: <p>I previously wrote a program that adds two fractions together and prints the output, simple I know. I originally implemented the program using structs and now I'm trying to re-implement it using classes, not so simple i guess... The problem is whenever I print the output it returns as zeros all across (double zeros for the denominator, I don't know why its doing that either), no matter what numbers I input. </p>
  
  <pre><code>Sample output:
  Enter First Numerator: 1
  Enter First Denominator: 2
  Enter Second Numerator: 1
  Enter Second Denominator: 4
  -------------------------
  0/00 + 0/00 = 0/00
  </code></pre>
  
  <p>Please look at my code and tell me what the problem is?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Fraction
  {
  private:
      int numerator;
      int denominator;
  public:
      Fraction()
      {
          numerator = 0;
          denominator = 0;
      }
  public:
      void set(int n, int d) {n = numerator; d = denominator;};
      int getNumerator() {return numerator;};
      int getDenominator() {return denominator;};
      Fraction addTo(Fraction &amp;frac2, Fraction&amp; frac3);
      int print() { cout &lt;&lt; numerator &lt;&lt; "/" &lt;&lt; denominator; return 0;};
  };
  //Adds the value of the Fraction with the attached "addTo" method with the value of a second   specified Fraction and assigns the result to a third specified Fraction.
  Fraction Fraction::addTo(Fraction&amp; frac2, Fraction&amp; addedTo)
  {
      frac2.numerator = (numerator * frac2.denominator) + (denominator * frac2.numerator);
      frac2.denominator = (denominator * frac2.denominator);
      frac2.numerator = addedTo.numerator;
      frac2.denominator = addedTo.denominator;
      return addedTo;
  }
  
  int main()
  {
  Fraction frac1, frac2, frac3;
  int n1, n2, d1, d2;
  
  //Prompts the user for data and then assigns it to the correct variables.
  cout &lt;&lt; "Enter First Numerator: ";
  cin &gt;&gt; n1;
  
  cout &lt;&lt; "Enter First Denominator: ";
  cin &gt;&gt; d1;
  
  cout &lt;&lt; "Enter Second Numerator: ";
  cin &gt;&gt; n2;
  
  cout &lt;&lt; "Enter Second Denominator: ";
  cin &gt;&gt; d2;
  
  frac1.set(n1, d1);
  frac2.set(n2, d2);
  
  frac1.addTo(frac2, frac3);
  
  //Formats output.
  cout&lt;&lt; "-------------------------\n"
      &lt;&lt; frac1.print() &lt;&lt; " + " &lt;&lt; frac2.print()&lt;&lt; " = " &lt;&lt; frac3.print() &lt;&lt; endl;
  cout &lt;&lt; "\n";
  
  return 0;
  }
  </code></pre>