Point Location

Hello,

I'd appreciate some help: here I managed to write some code, whose purpose is to give result TRUE(1) if point Z(a,b) is NOT in the circle with center f(c,d) and R. I've managed somehow to write a code which does not return any syntax or semantic errors, however, no matter what values if give to the variables, a,b,c,d and R, I get result 0 (or false). The task HAS to be based on a boolean expression. Here is the 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

// ConsoleApplication31.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "cmath"
#include "math.h"

#ifndef POINT_H
#define POINT_H
#include <cstdlib>
#endif

using namespace std;




struct point

{
	char Z;
	int a; int b;


};


struct K

{
	float c, d;
	float R;


};

int main()

{

	int a;
	cout << "a=";
	cin >> a;

	int b;
	cout << "b=";
	cin >> b;

	int c;
	cout << "c=";
	cin >> c;

	int d;
	cout << "d=";
	cin >> d;

	int R;
	cout << "R=";
	cin >> R;
	


	int DistanceZtoK = pow((a - c), 2) + pow((b - d), 2); 
	bool b1 = DistanceZtoK;
	bool b2 = pow(R, 2);
	cout << (b1 > b2) << endl;

	system("pause");





    return 0;
}

  

b1 and b2 are boolean. They can be true or false.

So when you try to make them equal to numbers on lines 66 and 67, it makes no sense. What's going on there?
Many, many thanks!!

I understand now, I'm trying to get used to the boolean type. When I read your answer, I knew instantly how to fix the problem, here's a code which gives True when point Z (a,b) is within a cirle with centr f(0,0), R=5 and point Z is in the 3rd quadrant, the code responded correctly. Thanks once again, I've been trying to figure it out since last night.

// ConsoleApplication31.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "cmath"
#include "math.h"

#ifndef POINT_H
#define POINT_H
#include <cstdlib>
#endif

using namespace std;




struct point

{
char Z;
int a; int b;


};


struct K

{
float c, d;
float R;


};

int main()

{

int a;
cout << "a=";
cin >> a;

int b;
cout << "b=";
cin >> b;

int c;
cout << "c=";
cin >> c;

int d;
cout << "d=";
cin >> d;

int R;
cout << "R=";
cin >> R;



int DistanceZtoK = pow((a - c), 2) + pow((b - d), 2);
bool b1 = DistanceZtoK < pow(R, 2);
bool b3 = a < 0 && a > -5 && b < 0 && b > -5;
cout << (b1 && b3) << endl;


system("pause");





return 0;
}

Topic archived. No new replies allowed.