I'm finding Harmonic numbers, the function cycles through until it finds the correct harmonic number as long as the line I was using to debug the program is input which was the cout line at the end. If I remove any portion of the cout, the program begins to fail again. I am at a complete loss as to how the cout is effecting the program. without it everything stores zeros.
struct fraction
{
long nume, denom;
};
void add (fraction x, fraction y, fraction& result)
{
long Numerator, Denominator, GCD, Higher, Lower;
Numerator = (x.nume * y.denom + x.denom * y.nume);
Denominator = (x.denom * y.denom);
if (Numerator > Denominator)
{
Lower = Denominator;
Higher = Numerator;
}
else if (Numerator < Denominator)
{
Higher = Denominator;
Lower = Numerator;
}
while (Higher % Lower > 0)
{
GCD = Higher % Lower;
Higher = Lower;
Lower = GCD;
}
result.nume = Numerator/GCD;
result.denom = Denominator/GCD;
cout << "d " << result.nume << " " << GCD << " " << Denominator/GCD << " " << result.denom << endl;
}