Error Message Matching Opperands

I have the following code but have the error message "no operator "=" matches these opperands in a few places and do not know how to fix it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;

class Rational
{
private:
int numerator;
int denominator;
int d;
int x;

public:
Rational(int num = 0, int den = 1);
void addition(Rational c);
void subtraction(Rational c);
void multiplication(Rational c);
void division(Rational c);
void printRational();
void printRationalAsDouble();

private:
void reduce();
};

Rational::Rational(int num, int den) : numerator(num), denominator(den)
{}

void Rational::addition(Rational c)
{
numerator = numerator + c.numerator;
denominator = denominator + c.denominator;
reduce();
}


void Rational::subtraction(Rational c)
{
numerator = numerator - c.numerator;
denominator = denominator - c.denominator;
reduce();
}

void Rational::multiplication(Rational c)
{
numerator = numerator * c.numerator;
denominator = denominator * c.denominator;
reduce();
}

void Rational::division(Rational c)
{
numerator = numerator * c.denominator;
denominator = denominator * c.numerator;
reduce();
}

void Rational::printRational()
{
	cout << numerator << "/" << denominator;
}

void Rational::printRationalAsDouble()
{
	cout << d / static_cast<float>( x );
}


void Rational::reduce()
{
	int largest;
	largest = numerator > denominator ? numerator : denominator;

	int gcd = 0;

	for(int loop = 2; loop <= largest; loop++)
		if(numerator % loop == 0 && denominator % loop == 0)
			gcd = loop;
	if(gcd != 0)
	{
		numerator /= gcd;
		denominator /= gcd;
	}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Exercise 9.6 Solution: Ex09_06.cpp
#include<iostream>
using std::cout;
using std::endl;

#include "Rational.h" // include definition of class Rational

int main()
{
   Rational c( 2, 6 ), d( 7, 8 ), x; // creates three rational objects 

   c.printRational(); // prints rational object c
   cout << " + ";
   d.printRational(); // prints rational object d				
   x = c.addition( d ); // adds object c and d; sets the value to x

   cout << " = ";
   x.printRational(); // prints rational object x
   cout << '\n';
   x.printRational(); // prints rational object x    
   cout << " = ";
   x.printRationalAsDouble(); // prints rational object x as double
   cout << "\n\n";

   c.printRational(); // prints rational object c
   cout << " - ";
   d.printRational(); // prints rational object d
   x = c.subtraction( d ); // subtracts object c and d 
           
   cout << " = ";
   x.printRational(); // prints rational object x
   cout << '\n';
   x.printRational(); // prints rational object x
   cout << " = ";
   x.printRationalAsDouble(); // prints rational object x as double
   cout << "\n\n";

   c.printRational(); // prints rational object c
   cout << " x ";
   d.printRational(); // prints rational object d
   x = c.multiplication( d ); // multiplies object c and d
                            
   cout << " = ";
   x.printRational(); // prints rational object x
   cout << '\n';
   x.printRational(); // prints rational object x
   cout << " = ";
   x.printRationalAsDouble(); // prints rational object x as double
   cout << "\n\n";

   c.printRational(); // prints rational object c
   cout << " / ";
   d.printRational(); // prints rational object d	
   x = c.division( d ); // divides object c and d
                            
   cout << " = ";
   x.printRational(); // prints rational object x		
   cout << '\n';
   x.printRational(); // prints rational object x
   cout << " = ";
   x.printRationalAsDouble(); // prints rational object x as double
   cout << endl;
          system("pause");
   return 0;
} // end main 
Topic archived. No new replies allowed.