# Thread: few errors when compiling one of them is the inverse function what to return

1. ## few errors when compiling one of them is the inverse function what to return

Code:
```#include <iostream>
#include <cmath>
using namespace std;

class rational
{
public:

rational();
rational sub(rational);
rational mul(rational);
rational div(rational);
rational inv(rational);
int getdenominator();
int getnumerator();
void print(rational);
private:
int numerator;
int denominator;

};

void rational::print(rational)//make sure it is right
{

cout << numerator << "/" << denominator << endl;
}

rational rational::inv(rational b)
{
return rational.reciprocal(b.getdenominator(),b.getnumerator());//added .  not sure if it is right
}
rational rational(int num ,int den )//i added rational the class name in t he front
{
int numerator=num;
int denominator=den;
}
{
{
int num1 = (this.numerator * b.denominator) + (b.numerator * this.denominator); // cross multily and add
int    num2 = this.denominator * b.denominator; // multiply the denominators to make them equivlent
}
rational rational::sub(rational b)
{
int num1 = (this.numerator * b.denominator) - (b.numerator * this.denominator);// cross multiply and subtact
int num2 = this.denominator * b.denominator;

}
rational rational::mul(rational b)
{
int num1 = this.numerator * b.numerator; // multiplys straight accross
int    num2 = this.denominator * b.denominator;

}
rational rational::div(rational b)
{
rational reciprocal=inv(b);
int num1=numerator*reciprocal.numerator;
int num2=denominator*reciprocal.denominator;
/* int num1 = this.numerator * b.denomerator; //multiplys the inverse of 2nd fraction object to divide
int num2 = this.denomerator * b.numerator;
*/

}

int main()
{
rational c(4,2);
rational d(8,4);
rational x;

a.print();
b.print();
cout << " = ";
x.print();
cout << '\n';
x.print();
cout << " = ";
cout << "\n\n";

c.print();
cout << " subtraction ";
d.print();
x = c.sub(d);
cout << " = ";
x.print();
cout << '\n';
x.print();
cout << " = ";
cout << "\n\n";

c.print();
cout << " multiplication ";
d.print();
x = c.mul(d);
cout << " = ";
x.print();
cout << '\n';
x.print();
cout << " = ";
cout << "\n\n";

c.printRational();
cout << " division ";
d.printRational();
x = c.div(d);
cout << " = ";
x.printRational();
cout << '\n';
x.printRational();
cout << " = ";
cout << endl;
system("pause");
return 0;
}```

2. I see some comments in the code, but none of them seem to indicate what the "errors when compiling" are.

3. This
Code:
```rational rational::inv(rational b)
{
return rational.reciprocal(b.getdenominator(),b.getnumerator());//added .  not sure if it is right
}```
I guess?

4. You need to look at the errors the compiler gives you and start with the first one.

I can tell that you're unfamiliar with C++ syntax. If you are new, you shouldn't be writing this much code at a time.

5. Originally Posted by NeonBlack
You need to look at the errors the compiler gives you and start with the first one.

I can tell that you're unfamiliar with C++ syntax. If you are new, you shouldn't be writing this much code at a time.
I strongly agree with both of those. Write one function, get it to compile and produce the correct output, and then start the next one.

For now, how about commenting out add, sub, mul, div, and inv, and just get it printing out the initial value of c correctly. You've done at least two different things wrong in your constructor, so start doing some research about what the proper syntax for that is.