I'm trying to write a fraction class and I want a function to reduce the fraction to lowest terms. The problem I'm having is trying to get the fractions to reduce. I need a way to find a common factor in both numbers. All other functions work the way I want them to.
class Fraction{
private:
int numerator;
int denominator;
public:
Fraction(){
}
void setNumerator(int numerator){
this->numerator=numerator;
}
void setDenominator(int denominator){
this->denominator=denominator;
}
int getNumerator(){
return numerator;
}
int getDenominator(){
return denominator;
}
int reduce(){
if(denominator%numerator==0){
return denominator/numerator;
}
else{
return 0;
}
}
};