# Thread: syntax errors

1. 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;

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.

2. you should check your GDC function in debugger... it has some logical errors
or add traces after each step...

3. It worked before I had to add the fractions together.

4. I suppose it worked but not for all possible inputs
Code:
```int GCD(int a, int b )
{
do
{
int big = max(a,b);
int small = min(a,b);
a = big%small;
b = small;
}while(a);
return b;
}```

Popular pages Recent additions