Classes

I'm having two errors and i don't know why? Please some help will be appreciated. Thanks
Here's my code..

// This program uses a class to compute the inverse of two numbers
// and convert them to decimal
#include <iostream>
using namespace std;

class Ratio
{
private:
double x;
double y;
public:
void assign(double , double);
double convert();
void invert ();
void print ();
};

void Ratio :: assign (double a, double b)
{
x = a;
y = b;
}

double Ratio :: convert ()
{
double m;
m = x/y;
return m;
}

void Ratio :: invert()
{
int temp;
temp = x;
x = y;
y = temp;

cout << x << "/" << y <<endl;

}

void Ratio :: print()
{
cout << x << "/" << y << endl;

}

int main()
{
Ratio rat;
double q, p;
cout << "Enter two numbers" << endl;
cin >> q >> p;

rat.assign(q , p);

cout << "The numbers you entered are :"<< rat.print()<<endl ;//gives an error here

cout << "Their inverse is :"; << rat.invert()<<endl ;// also gives an error here
cout << " Their decimal ratio : " << rat.convert()<<endl;

return 0;
}









Can you let us know what error you are getting ?
Hi ,
I think that the main function should be as below .


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main(int argc, char* argv[])
{
	Ratio rat;
	double q, p;
	cout << "Enter two numbers" << endl;
	cin >> q >> p;

	rat.assign(q , p);

	cout << "The numbers you entered are :";
	rat.print();

	cout << "Their inverse is :"; 
	rat.invert();// also gives an error here
	cout << " Their decimal ratio : " << rat.convert()<<endl;

	return 0;
}
Both functions return nothing (return type is void), so there's no return value.
Thanks for help... that was it!!!!
Topic archived. No new replies allowed.