Click here to Skip to main content
15,399,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

What I have tried:

C++
#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();
}
Posted
Updated 14-Dec-21 22:02pm
v2
Comments
jeron1 14-Dec-21 12:15pm
   
"But I have errors" - can you elaborate?
Richard MacCutchan 14-Dec-21 12:32pm
   
"But I have errors and I don't know how to solve them."
Nor do we, because we have no idea what the errors are, or where they occur.
Rick York 15-Dec-21 1:54am
   
If you are just squaring values I recommend against using the pow function to do that. It is very inefficient for that purpose. It would be better to write a square function and call that. It can be inline or templated so it will be much faster. The pow function uses a logarithm, an exponential function, and a multiply whereas a square function will be a single multiply and that's all. The pow function is made that way because it needs to deal with real exponents. If you only use integer exponents then a custom power function would be a better option. I made myself square and cube functions because those are as high an exponent as I ever work with.

1 solution

Start with the very first error in your list of compile errors and fix it.

In your case it could well be
C++
#include<conio.h>
in which case just comment out that line and get rid of the getch(); for now.

On line 30 you are going to get an error on
C++
Br[i] = 0;
Quote:
'i' was not declared in this scope
The only place you declare i is in the for-loop further up your code - so that definition has gone out of scope. See Scope (C++) | Microsoft Docs[^]

Bear in mind - you not only have to declare i but need to assign it a value before attempting to use it to index your array

The next error is likely to be on your use of the pow function - include the correct header for that

Continue through your compiler error list one by one, starting at the top and recompiling after every fix that you apply
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900