Function not returning correct value

I have a structure containing string, int and double. My function takes four doubles and compares it to the double from structure. But it's returning wrong value, (always true), and when I try to print out the double from structure in main prints out some kind of address.
part of header file:
1
2
3
4
5
6
7
8
9
  struct aut{
    std::string reg;
    double dom;
    int bropu;

    aut();
    aut(std::string reg, double dom, int broput);

    bool distance(double x1, double y1, double x2, double y2); };

declaration of function:
1
2
3
4
5
double aut::distance(double x1, double y1, double x2, double y2){
    double dx = x1 - x2, dy = y1 - y2;
    double distance= sqrt(dx * dx + dy * dy);
  return(distance < dom)
  };


main:
1
2
3
4
int main(void) {

aut a1("first", 500.0, 6);
cout << a1.distance(10.0, 10.0, 20.0, 20.0) << endl;



Thank you!
What is the body of the constructor? Does it set dom properly?

Also note that the declaration returns a bool, but the definition returns a double!

Perhaps:

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
#include <string>
#include <iostream>
#include <cmath>

struct aut {
	std::string reg;
	double dom {};
	int bropu {};

	aut() {}
	aut(const std::string& r, double d, int b) : reg(r), dom(d), bropu(b) {}

	bool distance(double x1, double y1, double x2, double y2);
};

bool aut::distance(double x1, double y1, double x2, double y2) {
	const double dx = x1 - x2, dy = y1 - y2;
	const double distance = std::sqrt(dx * dx + dy * dy);

	return distance < dom;
};

int main()
{
	aut a1("first", 5.0, 6);

	std::cout << a1.distance(10.0, 10.0, 20.0, 20.0) << '\n';
}


sorry, bool and double switch is mistake I left double when I tried testing if function would printing correct dom, if I set return dom.
constructor for structure:
1
2
3
4
5
6
7
8
9
aut::aut(string reg, double dom, int bropu) {
string reg1;
reg1 = reg;
double dom1;
dom1 = dom;
int bropu1;
bropu1=bropu;

};


when I try to print out dom and other elements of structure inside the constructor, it prints out correct, but not in main.
The constructor is wrong. See mine above.
Thank you very much!
Topic archived. No new replies allowed.