Ok a few thought. First the updated code doesn't compile.
Line 5
|
void getrec(double x[], double y[]);
|
should agree with line 20
|
int getrec(double x[], double y[])
|
Line 17 gives an error
|
polar(x, y, distance, angle);
|
because x and y are arrays but the function polar is expecting a single value of type double.
For example
|
polar(x[0], y[0], distance, angle);
|
would call the function with the first element of the arrays x and y.
... I'm getting a rather unnerving sense of deja vu here ...
Line 34
|
void polar(double x, doube y, double& r, double& theta)
|
the type
double
has mysteriously changed into
doube
.
Ok, having gone through that I've an uneasy feeling. If the code doesn't compile, then you cannot run it. If it isn't actually running, then trying to either check that it works, or make any enhancements won't be easy.
Now for some of the other questions,
At line 30
Since count is set to 50, how does that check whether the user entered (0,0)? |
A minor point, which I'll mention and then skip over - SIZE if a better alternative than 50 here.
Now, how does it check check whether the user entered (0,0)?
This needs breaking down into smaller steps.
Line 30 looks like this:
|
while(count <= 50 && x[count -1] && y[count -1]);
|
The first thing to notice is the use of && to combine expressions. There are three individual conditions:
Since the
&&
(logical AND) operator is used, that means the loop will continue to execute only when all three of these are true.
By now you are probably puzzled.
count <= 50
l
ooks like a condition. But what about the other two? Well in both C and C++ any value which evaluates as
zero is considered as meaning logical
false
. Conversely, any value or expression which is
not zero means logical
true
.
Now we've taken this apart, we can see a few problems.
This is the problem requirement:
The user may enter up to 50 pairs, and the user will say he/she is done by inputting the coordinate pair (0, 0). |
Not it says
up to 50. But testing
count <= 50
allows the loop to execute one more time when count has reached 50 (count is equal to 50) thus the user may enter 51 values. That is dangerous. Where will that 51st pair of values be stored? Not inside the arrays. They are already completely full. Some adjacent area of memory will be corrupted. The condition should be
count < 50
, with the 'less than' operator, not 'less than or equal to'.
The other conditions are not quite right. (0,0) is supposed to mark the end of input. Currently if something like (0,7) or (5, 0) is entered, it will terminate the loop.
This reply is getting quite long, so I'll end there. I know there are other questions, but I can only recommend getting the program up and running, start testing it with actual input before considering any next move to make.