Help in a lot of fraction in c++

Hi!
The program is running well but i need to help how to reduce the fraction. when I enter 2, -3 , 5, 6 the output gives -10/18 instead of -5/9. This is my program someone can help me how i can fix it.
#include <cstdlib>
#include<iostream>
using namespace std;
//create their own data types. Perhaps the simplest method for doing so is via an
//enumerated type. An enumerated type is a data type
//where every possible value is defined as a symbolic constant (called an enumerator).
enum Menu_Arthmetic_Choice {
None = 0,
Menu_Add = 1,
Menu_Subtract =2,
Menu_Multiply = 3,
Menu_Divide = 4,
Menu_Quit = 5,
End = 6,

};

//Passing structure to functions
struct Fractions //Holds data for Fractions input
{
int resultNum;
int resultDen;
int num1;
int num2;
int den1;
int den2;
};
//Function Prototypes
int menu();
void addFractions(Fractions, int &resultNum, int &resultDen);
void subtractFractions(Fractions, int &resultNum, int &resultDen);
void multiplyFractions(Fractions, int &resultNum, int &resultDen);
void divideFractions(Fractions, int &resultNum, int &resultDen);
void showResults(Fractions, int resultNum, int resultDen, int operation);
void readFractionValues(Fractions &);
int SimplifyFraction(int &resultNum, int &resultDen);
int Simplify(int &resultNum, int &resultDen);


int main()
{
Fractions input;
int menuArthmeticChoice = None;
int resultNum = 0;
int resultDen = 0;

do
{
menuArthmeticChoice = menu();

// I used if instead of switch statement because it is more efficiency than switch statement
if (menuArthmeticChoice == Menu_Quit)
break;
//Call The functions

readFractionValues(input);
//If choice is "addfractions" then
if (menuArthmeticChoice == Menu_Add)
{
addFractions(input, resultNum, resultDen);
}

//If choice "subtractfractions" so
if (menuArthmeticChoice == Menu_Subtract)
{
subtractFractions(input, resultNum, resultDen);
}

//If choice "multiplyfraction" so
if (menuArthmeticChoice == Menu_Multiply)
{
multiplyFractions(input, resultNum, resultDen);

}
//If choice "divivefraction" so
if (menuArthmeticChoice == Menu_Divide)
{
divideFractions(input, resultNum, resultDen);
}

SimplifyFraction(resultNum, resultDen);


//Simplify(resultNum, resultDen);
// sam(resultNum, resultDen);
//Show results
showResults(input, resultNum, resultDen, menuArthmeticChoice);

} while (menuArthmeticChoice != Menu_Quit);
return 0;

}
/*******************************
*A menu for choice of arithmetic*
*operations, in which the user *
*can make repeated choices *
*********************************/
int menu()
{
int menuChoiceOfArithmetic = 0;
do
{
// 1-Add Fractions
cout << "1- Add Fraction" << endl;
//2-Subtract Fractions
cout << "2- Subtract Fraction" << endl;
//3-Multiply Fractions
cout << "3- Multiply Fraction" << endl;
//4-Divide Fractions
cout << "4- Divide Fraction" << endl;
//5-Quit
cout << "5-Quit" << endl;
//make a choice
cout << "Ensert a number of choice" << endl;
cin >> menuChoiceOfArithmetic;

if (menuChoiceOfArithmetic <= None || menuChoiceOfArithmetic >= End)
cout << "Invalid menu choice. Please try again." << endl;
}
//End Menu_Arthmetic_Choice loop
while (menuChoiceOfArithmetic <= None || menuChoiceOfArithmetic >= End);

//Return valid Menu_Arthmetic_Choice
return menuChoiceOfArithmetic;
}
/*****************************************************************
*readFractionValues function: gets fraction values directly *
*from user. *
******************************************************************/

void readFractionValues(Fractions &input)
{
cout << "Enter denomitor for first fraction: ";
cin >> input.den1;

cout << "Enter numerator for first fraction: ";
cin >>input. num1;

cout << "Enter denomitor for second fraction: ";
cin >> input.den2;

cout << "Enter numerator for second fraction: ";
cin >> input.num2;
cout << endl;

}


/*****************************************************************
*addFractions function: adds two fractions using input provided and*
*display the results. *
******************************************************************/
void addFractions(Fractions input, int &resultNum, int &resultDen)
{

resultNum = (input.den1 * input.num2) + (input.den2 *input. num1);
resultDen =input. num1 * input.num2;



}

/*****************************************************************
*subtrctFractions function: subtractes two fractions using input *
*provided and display the results. *
******************************************************************/
void subtractFractions(Fractions input, int &resultNum, int &resultDen)
{
resultNum = (input.den1 * input.num2) - (input.den2 *input.num1);
resultDen = input.num1 * input.num2;
}

/*****************************************************************
*multiplyFractions function: multiplies two fractions using input *
*provided and display the results. *
******************************************************************/

void multiplyFractions(Fractions input, int &resultNum, int &resultDen)
{
resultNum = input.den1 * input.den2;
resultDen = input.num1 * input.num2;
}

/*****************************************************************
*divideFractions function: divides two fractions using input *
*provided and display the results. *
******************************************************************/

void divideFractions(Fractions input, int &resultNum, int &resultDen)
{
resultNum = input.den1 * input.num2;
resultDen = input.den2 * input.num1;
}



int SimplifyFraction(int &resultNum, int &resultDen)
{
//For the output 1.
/*if ((resultNum < 0 && resultDen > 0) || (resultNum > 0 && resultDen < 0))
//return resultDen;
{
if (resultNum > 0)
{

resultNum *= -1;
}
resultDen = resultDen;
}*/
/////////////////////////////////////////////////
// For the output 2
if (resultDen < 0 && resultNum > 0)
{
resultNum = -resultNum;
resultDen = -resultDen;
}
////////////////////////////////////////////
//Reduce the fractions
for (int i = resultNum*resultDen; i > 1; i--)
{
if ((resultNum % i == 0) && (resultDen % i == 0))
{
resultNum /= i;
resultDen /= i;

}
}


return (resultNum, resultDen);

}

/*****************************************************************
*showResults function:Displays the fractions and results *
*in equation form. *
******************************************************************/

void showResults(Fractions input, int resultNum, int resultDen, int operation)
{
//If operation ADD
if (operation == Menu_Add)
{
cout << input.den1 << '/' << input.num1 << '+' << input.den2 << '/' << input.num2 << '=' << resultNum << '/' << resultDen << endl;
}

//If operation Subtract
if (operation == Menu_Subtract)
{
cout << input.den1 << '/' << input.num1 << '-' << input.den2 << '/' << input.num2 << '=' << resultNum << '/' << resultDen << endl;
}

//If operation Multiply
if (operation == Menu_Multiply)
{
cout <<input.den1 << '/' << input.num1 << '*' << input.den2 << '/' << input.num2 << '=' << resultNum << '/' << resultDen << endl;
}
//If operation Divide
if (operation == Menu_Divide)
{
cout << input.den1 << '/' << input.num1 << '/' << input.den2 << '/' << input.num2 << '=' << resultNum << '/' << resultDen << endl;
}
}
Put the code you need help with here.
[/code]
Divide the numerator and denominator by the GCD of the two numbers.

You can compute GCD using the Euclidean algorithm:
http://en.wikipedia.org/wiki/Euclidean_algorithm
Topic archived. No new replies allowed.