fuction parameter passing error

why the value is not passing between function what is wrong with this code.

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
  #include<iostream>
using namespace std;
struct rational {
   int numerator;
   int denominator;
};

void reduce(struct rational *r1, struct rational *or1) {
   
int p,q,i,max;
if(r1.numerator>r1.denominator) max = r1.numerator;
     else max=r1.denominator;
     p=r1.numerator;
     q=r1.denominator;
     for(i=2;i<=max/2;i++)
     {
	  if(r1.numerator%i ==0 && r1.denominator%i ==0)
	  {
		r1.numerator/=i;
		r1.denominator/=i;
		}
	  }
or1.numerator=r1.numerator;
or1.denominator=r1.denominator;
cout<<"The reduced form of"<<p<<"/"<<q<<"="<<or1.numerator<<"/"<<or1.denominator<<endl;

	
}


bool isEqual(struct rational num1, struct rational num2) {
    
rational or1,or2;
reduce(num1,or1);
reduce(num2,or2);
if(or1.numerator==or2.numerator && or1.denominator==or2.denominator)
 return true;
else 
return false;
}

int main(void)
{
	
	rational r1,r2; char c;
	
	
	cout<<"Enter two rational numbers: ";
	cin >>r1.numerator>>c>>r1.denominator>>r2.numerator>>c>>r2.denominator;
isEqual(r1,r2);
}
Last edited on
void reduce(struct rational *r1, struct rational *or1)
Your function expects 2 pointer but you pass normal variables inside isEqual.
1
2
rational or1,or2;
reduce(num1,or1);

Also you need the -> operator for pointers.
1
2
3
4
5
6
void reduce(struct rational *r1, struct rational *or1) 
{
   if (r1->numerator > r1->denominator) 
   ...
}


Topic archived. No new replies allowed.