### Help C++

There are set K circles (the abscissa and the horde of the center and radius) and m (m<=20) points (abscissa and ordin) are set. write a program to determine how many circles each point lies in.

But I have errors and I don't know how to solve them.
<
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;

int main() {
system("chcp 1251");
int k; //Circle numbers
int m; //Point numbers
float x[20], y[20],
X[20], Y[20],
R[10];
cout << "Number of points:"; cin >> k;
for (int i = 0; i < k; i++)
{
cout << i << "-Circle: \n";
cout << "X:"; cin >> X[i];
cout << "Y:"; cin >> Y[i];
cout << "R:"; cin >> R[i];
}
//Въвеждане на данните а точките
for (int j = 0; j < 20; j++) {
cout << j << "-point:\n";
cout << "x:"; cin >> x[j];
cout << "y:"; cin >> y[j];
}
int Br[20]; //Number of circles
for (int j = 0; j < m; j++)
{
Br[i] = 0;
for (int i = 0; i < k; i++)
if (pow(x[j] - X[i], 2) + pow(y[j] - Y[i], 2) <= pow(R[i], 2)) Br[i]++;
}
//Result - Number of Circles
for (int i = 0; i < m; i++) cout << Br[i] << endl;
getch();
}
>
Next time, post the errors you get. Don't make us find them.
 ``` In function 'int main()': 33:8: error: 'i' was not declared in this scope 35:27: error: 'pow' was not declared in this scope```

pow is found within #include <cmath>.
i does not exist on the line you're trying to access it on.
 ``12345678`` `````` int Br[20]; //Number of circles for (int j = 0; j < m; j++) { Br[i] = 0; for (int i = 0; i < k; i++) if (pow(x[j] - X[i], 2) + pow(y[j] - Y[i], 2) <= pow(R[i], 2)) Br[i]++; }``````

Perhaps you meant j, for both lines where you access Br[i]? Otherwise, you are also potentially incrementing Br[i] before initializing it.
Last edited on
Reformatted gives:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include #include //#include using namespace std; int main() { //system("chcp 1251"); int k; //Circle numbers int m; //Point numbers float x[20], y[20], X[20], Y[20], R[10]; cout << "Number of points:"; cin >> k; for (int i = 0; i < k; i++) { cout << i << "-Circle: \n"; cout << "X:"; cin >> X[i]; cout << "Y:"; cin >> Y[i]; cout << "R:"; cin >> R[i]; } for (int j = 0; j < 20; j++) { cout << j << "-point:\n"; cout << "x:"; cin >> x[j]; cout << "y:"; cin >> y[j]; } int Br[20]; //Number of circles for (int j = 0; j < m; j++) { Br[i] = 0; for (int i = 0; i < k; i++) if (pow(x[j] - X[i], 2) + pow(y[j] - Y[i], 2) <= pow(R[i], 2)) Br[i]++; } //Result - Number of Circles for (int i = 0; i < m; i++) cout << Br[i] << endl; //getch(); }``````

L38, L47 - m is used but it's value is not set anywhere??

L39 - i is used but is not initialised - is j meant (also L43)?

Last edited on
Didn't we already suggest you to post code with code tags? See https://www.cplusplus.com/articles/jEywvCM9/

You "have errors". There "is solution". You have to describe those errors in detail if you want more detailed answer.
I make new code but i make at how many points each circle lies, but i don't know how to make code for in how many circles lies each point.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include #include #include using namespace std; int main() { system("chcp 1251"); int k,//-Number of circles m;//- Number of points float x[20], y[20], X[10], Y[10], R[10]; //Enter circles data cout << "Number of circles:"; cin >> k; for (int i = 0; i < k; i++) { cout << i << "-of Circle: \n"; cout << "-the abc of the center:"; cin >> X[i]; cout << "-the horde of the center:"; cin >> Y[i]; cout << "-the radius of the circumference:"; cin >> R[i]; } //Entering points data cout << "Number of points:"; cin >> m; for (int j = 0; j < m; j++) { cout << j << "-Point:\n"; cout << "-the abscissa of the point:"; cin >> x[j]; cout << "-the horde of the point:"; cin >> y[j]; } int br[10]; for (int i = 0; i < m; i++) { br[i] = 0; for (int j = 0; j < m; j++) if (pow(x[j] - X[i], 2) + pow(y[j] - Y[i], 2) <= pow(R[i], 2)) br[i]++; } //Results for (int i = 0; i < m; i++) cout << br[i] << endl; //getch(); }``````
 ``123456789101112`` ``````for( int i = 0 ; i < num_points ; ++i ) // for each point (outer loop) { int cnt = 0 ; // count of how many circles this point lies in for( int j = 0 ; j < num_circles ; ++j ) // for each circle (inner loop) { // increment cnt if point #i lies in circle #j if( point_#i_lies_in_circle_#j ) ++cnt ; // pseudocode } print x, y, cnt // pseudocode }``````
Topic archived. No new replies allowed.