#include "hw11.h" int main() { Fraction fract_1, fract_2; cin >> fract_1 >> fract_2; int power; cout << "Enter a positive integer power to raise the fraction to >>> "; cin >> power; cout << endl; cout << "The entered fraction, reduced is "<< fract_1 << endl << "The entered fraction, reduced is " << fract_2 << endl << endl; // addition Fraction fract_3 = fract_1 + fract_2; cout << "fraction 1 + fraction 2 = " << fract_3 << endl << endl; // subtraction fract_3 = fract_1 - fract_2; cout << "fraction 1 - fraction 2 = " << fract_3 << endl << endl; // multiplication fract_3 = fract_1 * fract_2; cout << "fraction 1 * fraction 2 = " << fract_3 << endl << endl; // division fract_3 = fract_1 / fract_2; cout << "fraction 1 / fraction 2 = " << fract_3 << endl << endl; // power fract_3 = fract_1 ^ power; cout << "fraction 1 ^ " << power << " = " << fract_3 << endl << endl; return 0; }

Here is the header file that must use the input of power:

#include<iostream> using namespace std; class Fraction { private: int numerator1, denominator1; public: Fraction(){numerator1 = -99999; denominator1 = -99999;} int getNumerator1() const {return numerator1;} int getDenominator1() const {return denominator1;} void setNumerator1(int N) {numerator1 = N;} void setDenominator1(int D) {denominator1 = D;} int Reduce(); int Sign; int numerator; int power; Fraction operator+ (Fraction&); Fraction operator- (Fraction&); Fraction operator* (Fraction&); Fraction operator/ (Fraction&); Fraction operator^ (int power); friend istream& operator >> (istream&, Fraction&); friend ostream& operator << (ostream&, Fraction&); }; istream& operator >> (istream& in, Fraction& F) { int FirstNum = 0; int SecondNum = 0; char thing; cout << "Enter a fraction in the form \"numerator/denominator\" >>> "; in >> FirstNum >> thing >> SecondNum; F.numerator1 = FirstNum; F.denominator1 = SecondNum; return in; } ostream& operator << (ostream& out, Fraction& F) { F.Reduce(); int count = 0; if(F.numerator > F.denominator1) { int remainder = F.numerator%F.denominator1; while(F.numerator >= F.denominator1) { count++; F.numerator -= F.denominator1; } out << F.Sign * count << " " << remainder << "/" << F.denominator1; } else { out << F.numerator1 << "/" << F.denominator1; } if(F.numerator1 == F.denominator1) { out << 1; } return out; } int Fraction::Reduce() { Sign = 1; if (numerator1 == 0 || denominator1 == 0) { denominator1 = 1; return 0; } else { if(numerator1 < 0) { Sign = -1; numerator1 = -1 * numerator1; } if(denominator1 < 0) { Sign = -1; denominator1 = -1 * denominator1; } } int GCD = numerator1; int Dum = denominator1; while(GCD != Dum) { if(GCD > Dum) { GCD = GCD - Dum; } if(Dum > GCD) { Dum = Dum - GCD; } if(GCD == Dum) { break; } } numerator = (numerator1/GCD); numerator1 = Sign * (numerator1/GCD); denominator1 = denominator1/GCD; return numerator, numerator1, denominator1; } Fraction Fraction::operator+ (Fraction& F) { Fraction Add; Add.numerator1 = numerator1 * F.denominator1 + F.numerator1 * denominator1; Add.denominator1 = denominator1 * F.denominator1; return Add; } Fraction Fraction::operator- (Fraction& F) { Fraction Sub; Sub.numerator1 = numerator1 * F.denominator1 - F.numerator1 * denominator1; Sub.denominator1 = denominator1 * F.denominator1; return Sub; } Fraction Fraction::operator* (Fraction& F) { Fraction Mult; Mult.numerator1 = numerator1 * F.numerator1; Mult.denominator1 = denominator1 * F.denominator1; return Mult; } Fraction Fraction::operator/ (Fraction& F) { Fraction Div; Div.numerator1 = numerator1 * F.denominator1; Div.denominator1 = denominator1 * F.numerator1; return Div; } Fraction Fraction::operator ^ (int power) { Fraction Pow; for(int i = 1; i = power; i++) { Pow.numerator1 = numerator1 * numerator1; Pow.denominator1 = denominator1 * denominator1; if(i = power) { break; } } return Pow; }

If I run what I have now, it only gives me the fraction to the second power no matter what power I input. What am I doing wrong?