0
#include "Rational.cpp"
using namespace std;

int main()
    {
     Rational r1, r2;
        cout << "c << ";
        cin >> r1;
        cout << "d << ";
        cin >> r2;

Rational add = r1 + r2;
Rational sub = r1 - r2;
Rational mul = r1 * r2;
Rational div = r1 / r2;

//sets up the euqation of the two fractions and shows the outcome
cout << r1 << " + " << r2 << " = " << add << endl;
cout << r1 << " - " << r2 << " = " << sub << endl;
cout << r1 << " * " << r2 << " = " << mul << endl;
cout << r1 << " / " << r2 << " = " << div << endl;

// check if one rational is greater than the other
cout << r1 << " > " << r2;
(r1 > r2) ? cout << " is true" << endl : cout << " is false" << endl;

// check if one rational is less than the other
cout << r1 << " < " << r2;
(r1 < r2) ? cout << " is true" << endl : cout << " is false" << endl;

// check if one rational is greater than equal to the other
cout << r1 << " >= " << r2;
(r1 >= r2) ? cout << " is true" << endl : cout << " is false" << endl;

// check if one rational is less than equal to the other
cout << r1 << " <= " << r2;
(r1 <= r2) ? cout << " is true" << endl : cout << " is false" << endl;

// check if two rationals are equal
cout << r1 << " == " << r2;
(r1 == r2) ? cout << " is true" << endl : cout << " is false" << endl;

// check if two rationals are not equal
cout << r1 << " != " << r2;
(r1 != r2) ? cout << " is true" << endl : cout << " is false" << endl;

return 0;

I have this bit of code I'm not sure how to go about fixing the no operator matches these operands error. In the check, if section I'm not sure what the full error is and what it's asking. I've tried changing around the formulas and such to get the error out but to no avail. It asks this error there and in the Rational add through div part at the start of the code as well.IM jus not fully sure what the error is asking and also how to fix it.

  • You've to overload the said/used operators for `Rational`. Refer to [What are the basic rules and idioms for operator overloading?](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) Also, **never include a source file**. – Jason Apr 06 '22 at 03:33
  • Is there any logical way to like un overload it or kinda restart the code and try an alternative way? – Dalton Mullis Apr 06 '22 at 03:34
  • 1
    Unrelated, whatever guide/book/site/person told you a 'solution' to anything is `#include`-ing a .cpp file, stop listening to them. Related to your problem, any operators used need definition. Chances are operators wouldn't be difficult to implement for `Rational`. Hard saying without seeing the code. – WhozCraig Apr 06 '22 at 03:34
  • For like example, the adding part of the code looks like this is this the cause? Rational Rational::operator+(const Rational& r) { int n = numerator * r.denominator + r.numerator * denominator; int d = denominator * r.denominator; Rational rr(n, d); return rr; } – Dalton Mullis Apr 06 '22 at 03:37
  • Relevant code belongs in the question please, ideally as part of a proper, complete, [mcve]. That said, see [this Q&A](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading). That's a heavy article on operator overloading a good practices for doing it. – WhozCraig Apr 06 '22 at 03:38
  • I ended up kinda figuring it out the basic fix suggestion in C++ for the resolution worked for that part I feel kinda dumb now, but now I have run into another issue – Dalton Mullis Apr 06 '22 at 03:48

0 Answers0