assigning structs to each other

Hi! I am having a problem with my code, at line 22 and 24 when i try to assign a struct to another struct i get the error "undefined reference to ReadPoint()" can anyone lend some assistance here?

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
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
struct Coordinate
{
	double latitude;
	double longitude;
	string name;
};
Coordinate ReadPoint();
void ComputeDistanceAndDirection(const Coordinate& pt1,const Coordinate& pt2,double distance,double azimuth);
double distancerads;
double azimuth=0.0;
const double pi = 3.141592;
int main()
{
	double distance;
	Coordinate pt1;
	Coordinate pt2;
	cout<<"Please enter the starting info";
	pt1=ReadPoint();
	cout<<"Please enter the ending info";
	pt2=ReadPoint();
	void ComputeDistanceAndDirection(const Coordinate& pt1,const Coordinate& pt2,double& distance,double& azimuth);
	distance=180*distancerads/pi;
	cout<<"To travel from"<<pt1.name<<"to"<<pt2.name<<endl;
	cout<<"Start direction (clockwise from North): "<<azimuth<<" degrees"<<endl;
	cout<<"Distance: "<<distance<<" km"<<endl;
}

Coordinate ReadPoint(double latitude,double longitude,string name)
{
	Coordinate Point;
	cout<<"Please enter the latitude";
	cin>>latitude;
	latitude=(latitude*pi)/180;
	cout<<"Please enter the longitude";
	cin>>longitude;
	longitude=(longitude*pi)/180;
	cout<<"Please enter the label";
	cin>>name;
	return(Point);
}
This function
Coordinate ReadPoint();
is defined but never implemented. You implement another overload of the function called ReadPoint(), but not the one taking no arguments.
ok so I have changed the function definition but I now get the error "too few arguments to function 'Coordinate ReadPoint"? Thanks for the help.

updated code is underlined

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
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
struct Coordinate
{
	double latitude;
	double longitude;
	string name;
};
Coordinate ReadPoint(double latitude,double longitude,string name);
void ComputeDistanceAndDirection(const Coordinate& pt1,const Coordinate& pt2,double distance,double azimuth);
double distancerads;
double azimuth=0.0;
const double pi = 3.141592;
int main()
{
	double distance;
	Coordinate pt1;
	Coordinate pt2;
	cout<<"Please enter the starting info";
	pt1=ReadPoint();
	cout<<"Please enter the ending info";
	pt2=ReadPoint();
	void ComputeDistanceAndDirection(const Coordinate& pt1,const Coordinate& pt2,double& distance,double& azimuth);
	distance=180*distancerads/pi;
	cout<<"To travel from"<<pt1.name<<"to"<<pt2.name<<endl;
	cout<<"Start direction (clockwise from North): "<<azimuth<<" degrees"<<endl;
	cout<<"Distance: "<<distance<<" km"<<endl;
}

Coordinate ReadPoint(double latitude,double longitude,string name)
{
	Coordinate Point;
	cout<<"Please enter the latitude";
	cin>>latitude;
	latitude=(latitude*pi)/180;
	cout<<"Please enter the longitude";
	cin>>longitude;
	longitude=(longitude*pi)/180;
	cout<<"Please enter the label";
	cin>>name;
	return(Point);
}
You are calling the function with too few arguments.
hmm but how would I go about fixing this? Thanks
Last edited on
When you defined the ReadPoint function your arguments were double latitude, double longitude, and string name. When you called it in main, you only called ReadPoint(), with no arguments. Although your ReadPoint function has cin, it only calls cin after you call ReadPoint.

Try erasing the three arguments of ReadPoint. Create the latitude, longitude, and name variables locally, and see if that works. Also, remember to use Point.latitude, Point.longitude, and Point.name (not just latitude, longitude, and name) when inputting the information about Coordinate Point.

As well, in your main function, line 25, you should call your ComputeDistanceAndDirection function without the "void" in front, nor the variable type of the arguments (const Coordinate&...etc). Also I do not see a definition of this function...you must implement it before using it!
Topic archived. No new replies allowed.