title: Fraction calculation
body: <p>I need to write a program that can calculate fractions using the operator that the user enters. I have different functions to reduce the fractions and find the greatest common denominator (which i'm not sure if i set them up correctly or not), and then I have the function calculate() to find the answer. I have to print out the final answer in fraction form and not decimal. </p>
  
  <p>The problem I am having is that I don't know how to return num3 and den3 from calculate() back into the main function. If anyone could help I would very gracious. Thank you.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>/*Problem: Write a program to manipulate fractions. It allows for the addition, subtraction, multiplication, or division of fractions.
      Inputs:
      Outputs:
  */
  
  #include &lt;iostream&gt;
  using namespace std;
  
  void calculate(int num1, int den1, int&amp; num3, int&amp; den3, int num2, int den2);
  void reduce(int&amp; num, int&amp; den);
  int gcd(int a, int b);
  
  int main(){
      int num1, num2, den1, den2, add, sub, mult, div;
      int op, calc;
      int num3, den3;
  
      cout &lt;&lt; "Enter the numerator of the first fraction" &lt;&lt; endl;
      cin &gt;&gt; num1;
      cout &lt;&lt; "Enter the denominator of the first fraction" &lt;&lt; endl;
      cin &gt;&gt; den1;
      cout &lt;&lt; "Enter the numerator of the second fraction" &lt;&lt; endl;
      cin &gt;&gt; num2;
      cout &lt;&lt; "Enter the denominator of the second fraction" &lt;&lt; endl;
      cin &gt;&gt; den2;
      cout &lt;&lt; "Enter a 1 for addition, 2 for subtraction, 3 for multiplication, or 4 for division" &lt;&lt; endl;
      cin &gt;&gt; op;
      calculate(op, num1, den1, num3, den3, num2, den2);
      cout &lt;&lt; "The answer using option: " &lt;&lt; op &lt;&lt; endl;
      cout &lt;&lt; "is " &lt;&lt; num3 &lt;&lt; " / " &lt;&lt; den3 &lt;&lt; endl;
  
  
  
      return 0;
  }
  
  void calculate(int op, int num1, int den1, int&amp; num3, int&amp; den3, int num2, int den2){
      if(op==1){
          num3 = num1 + num2;
          den3 = den1;
      }
      else if(op==2){
          num3 = num1 - num2;
          den3 = den1;
      }
      else if(op==3){
          num3 = num1 * num2;
          den3 = den1 * den2;
      }
      else if(op==4){
          num3 = num1 * den2;
          den3 = num2 * den1;
      }
  }
  
  void reduce(int&amp; num, int&amp; den){
      int reduced;
      reduced = gcd(num, den);
      num = num/reduced;
      den = den/reduced;
  
  }
  
  int gcd(int a, int b){
      int divisor=1, temp;
  
      while(b!= 0 || b&gt;a){ 
          temp = a % b; 
          a = b; 
          b = temp = divisor; 
      }
      while(a!=0 || a&gt;b){
          temp = b % a;
          b = a;
          a = temp = divisor;
      }
  
      return divisor;
  }
  </code></pre>