#include <iostream>
using namespace std;
struct Fraction {
int numerator;
int denominator;
};
int simplify(int numerator, int denominator) {
for (int i = denominator * numerator; i > 1; i--) {
if ((denominator % i == 0) && (numerator % i == 0)) {
denominator /= i;
numerator /= i;
}
}
}
int output(int numerator, int denominator) {
cout << numerator << "/" << denominator << endl;
}
int main() {
int num;
int den;
cout << "numerator: "; cin >> num;
cout << "denominator: "; cin >> den;
cout << endl;
cout << "entered: " << output(num, den) << endl;
cout << "simplified: " << simplify(num, den) << endl;
}
When I am running the code my first function is working but not the second function can you please help me with this? I have found this simplify function and trying to use it in my code but it is outputting exitted, illegal instruction. The simplify function must take struct Fraction as a parameter and return that Fraction in its reduced form. The output function must take struct Fraction as a parameter and print the fraction in the form "x/y". I am not sure how to use this struct in my code.
Example output:
numerator: 4
denominator: 8
entered: 4/8
simplified: 1/2