help with array plzzzz?
and this is my code
# include <iostream>
using namespace std;
class fraction
{
private:
int a;
int b;
public:
void get_fraction()
{
char slash = '\\';
cout<<"Enter Fraction:";
cin>>a>>slash>>b;
}
void print_fraction()
{
int c = gcd(a, b);
char slash = '\\';
cout<<a/c<<slash<<b/c<<"\t";
}
fraction fadd (fraction g1,fraction g2)
{
fraction total;
total.a =(g1.a*g2.b+g1.b*g2.a);
total.b=(g1.b*g2.b);
return total;
}
fraction fsub (fraction g1,fraction g2)
{
fraction total;
total.a=(g1.a*g2.b-g1.b*g2.a);
total.b=(g1.b*g2.b);
return total;
}
fraction fmul (fraction g1,fraction g2)
{
fraction total;
total.a=(g1.a*g2.a);
total.b=(g1.b*g2.b);
return total;
}
fraction fdiv (fraction g1,fraction g2)
{
fraction total;
total.a=(g1.a*g2.a);
total.b=(g1.b*g2.b);
return total;
}
void setA(int x)
{
a = x;
}
void setB(int x)
{
b = x;
}
int gcd(int x, int y)
{
int r;
while(y)
{
r = x % y;
x = y;
y = r;
}
return(x);
}
};
int main()
{
int count = 0;
char val;
fraction frac[100], sum, temp;;
sum.setA(0);
sum.setB(1);
do
{
frac[count].get_fraction();
cout<<"Would you like to continue(Enter'y' or 'n')? ";
cin>>val;
count++;
}while(val != 'n');
for(int i = 0; i<count; i++)
{
sum = sum.fadd(sum, frac[i]);
}
temp.setA(1);
temp.setB(count);
temp = temp.fmul(temp, sum);
cout<<"The average is : ";
temp.print_fraction();
cout<<endl;
return 0;
}
and it works fine but my teacher told me to change this code
void setA(int x)
{
a = x;
}
void setB(int x)
{
b = x;
}
int gcd(int x, int y)
{
int r;
while(y)
{
r = x % y;
x = y;
y = r;
}
return(x);
}
with is code
void lowterms()
{
long tnum,tden,temp,gcd;
tnum =labs(a);
tden =labs(b);
if(tden==0 )
{ cout<<"illegal fraction: division by 0";exit(1); }
else if (tnum==0)
{ a=0; b=1;return; }
while(tnum !=0)
{
if(tnum<tden)
{temp=tnum;tnum=tden; tden=temp;}
tnum=tnum-tden;
}
gcd=tden;
a=a/gcd;
b=b/gcd;
}
when I did that my program not working so what do I have to change in main () so it work please ??
thank youuuu :)

