title: How to implement greatest common divisor to simplify fractions
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int g_c_d(int n, int d);
  
  class Fraction
  {
  
  private:
    //variables to store numerator and denominator
    int num;
    int denom;
  
  public:
    Fraction(){}
    Fraction(int num): num(num) {}
    Fraction(int num, int denom): num(num), denom(denom) {}
  
    void set_num(int n){ num = n;}
    void set_denom(int d){ denom = d;}
  
    int get_numerator() const {return num;}
    int get_denominator() const {return denom;}
  };
  
    int g_c_d(int n, int d){
      return d == 0? n : g_c_d(d, n % d);
   }
  
  istream &amp;operator&gt;&gt; (istream &amp;input, Fraction &amp;f)
  {
    int n, d;
    char slash;
    input &gt;&gt; n;
    input &gt;&gt; slash;
    input &gt;&gt; d;
  
    if (d == 0) {n = 0;} //if denom is 0; fraction = 0/0
    f = Fraction(n, d);
    return input;
  }
  
  ostream &amp;operator&lt;&lt;(ostream &amp;output, const Fraction &amp;frac)
  {
    return output &lt;&lt; frac.get_numerator() &lt;&lt; "/" &lt;&lt; frac.get_denominator();
  }
  
  
  int main()
  {
     int n, d;
     Fraction frac;
  
     int gcd;
     n = frac.get_numerator();
     d = frac.get_denominator();
     gcd = g_c_d(frac.get_numerator() , frac.get_denominator());
  
     cout &lt;&lt; "Enter a fraction" &lt;&lt; endl;
     cin &gt;&gt; frac;
     frac.set_num(n/gcd);
     frac.set_denom(d/gcd);
     cout &lt;&lt; "your fraction is: ";
     cout &lt;&lt; frac &lt;&lt; endl;
  
     return 0;
  }
  </code></pre>
  
  <p>Hi im trying to simplify fractions entered by a user. However everytime I enter a fraction that is to be simplified the output returned is "1/0".</p>
  
  <p>Can some one please help, it'll be massively appreciated!</p>