it is giving me wrong output.
Code:
#include <iostream.h>
void addfraction (int w, int x, int y, int z, int& newnumerator, int& newdenominator)
{
int number1, number2;
number1=w*z;
number2=y*x;
newdenominator=z*x;
newnumerator=number1+number2;
};
int GCD(int a, int b )
{
int remainder, quotient, divisor, numerator;
if (a > b)
{
remainder=a%b;
quotient=a/b; divisor=b;
}
else
{
remainder=b%a;
quotient=b/a;divisor=a;
}
while( remainder!=0 )
{
numerator=divisor;
divisor=quotient;
remainder=numerator%divisor;
quotient=numerator/divisor;
}
return divisor;
}
int simplify(int a, int GCD )
{
int product;
{
{
product=a / GCD;
}
}
return product;
}
int main()
{
int w, x,y,z,a,b;
char junk;
cout << "Value of first numerator: ";
cin >> w;
cout << "Value of first denominator: ";
cin >> x;
cout << "Value of second numerator: ";
cin >> y;
cout << "Value of second denominator: ";
cin >> z;
addfraction(w,x,y,z,a,b);
cout << "\nThe Greatest Common Divisor of "
<< a << " and " << b << " is " << GCD(a, b) << endl;
cout << "\nThe simplified fraction of "
<< a << " and " << b << " is " << simplify(a,GCD(a, b)) << " and "<<
simplify(b,GCD(a, b)) << endl;
cout<<a<<'/'<<b<<endl;
cin >> junk; //This input allows for display.
//take care of improper fractions
return 0;
}
It is giving me huge numbers as answers. Also I am supposed to account for whole numbers and dont know how.