I got question how can i return the answer to display because i kept getting an error that void can't return a variable. How can i send it to my display function.
void Rational::add(const Rational&h2)
{
int num = 0;
int dem = 0;
add(h2);
int P = num * h2.dem + h2.num*dem;
int Q = dem*h2.dem;
}
void display() const; // _p:_q
{
if (Q == 1) // e.g. fraction 2/1 will display simply as 2
cout << P << endl;
else
cout <<P << "/" << Q << endl;
}
Aucun commentaire:
Enregistrer un commentaire