Structures not working correctly?

Posted by booby on Stack Overflow See other posts from Stack Overflow or by booby
Published on 2010-05-03T00:48:08Z Indexed on 2010/05/03 0:57 UTC
Read the original article Hit count: 201

Filed under:
Fraction AddFractions(const Fraction& frac1, const Fraction& frac2)
{
    Fraction frac3;

    if (frac1.denom == frac2.denom)
    {
        frac3.num = frac1.num + frac2.num;
        frac3.denom = frac1.denom;          
    }
    else
    {
        frac3.denom = (frac1.denom * frac2.denom);
        frac3.num = (frac1.num * frac2.denom) + (frac2.num * frac1.denom);          
    }
    return frac3;
}

This is my prototype and there is a structure defined as Fraction with int num and int denom when I call the function it just gives me back garbage? I don't know what's wrong with it. Please help. =( cout << "Please enter two Fractions" << endl; cout << endl; GetFraction(frac1); cout << "Your fisrt fraction is: "; PrintFraction(frac1); cout << endl; cout << endl; GetFraction(frac2); cout << "Your second fraction is: "; PrintFraction(frac2); cout << endl;

    do
    {
        choice1 = MathMenu();
        if (choice1 == ErrorOpt)
        {
            cout << "There was an error with what you have entered" << endl;
        }
        else if(choice1 != QuitOpt)
        {

            // do the math options 
            switch (choice1)
            {
            case AddOpt:
                AddFractions(frac1, frac2);
                break;
            case SubtractOpt:
                SubtractFractions(frac1, frac2);
                break;
            case MultiplyOpt:
                MultiplyFractions(frac1, frac2);
                break;
            case DivideOpt:
                DivideFractions(frac1, frac2);
                break;
            }
            //print the results 
            PrintFraction(frac1);
            PrintMathOption(choice1);
            PrintFraction(frac2);
            cout << " = ";
            Standardize(frac3);
            Reduce(frac3);
            PrintFraction(frac3);
            cout << endl;
            Pause();

© Stack Overflow or respective owner

Related posts about c++