alsnfaskdfas

fffd
Last edited on
ShiftX and ShiftY are arrays of values. You need to specify an index into the array to get a value.
ddd
Last edited on
For this error:
55:2: error: expected ';' before 'cout'
look at line 63-65


1
2
3
} while ((CoorX = 0) & (CoorY = 0));
return 0;
}


you missed a ;

In line 8-17,instead of giving a double function type,you can make the function as a void function type since the values you need are referenced.

While referencing an array,the name of the array acts as a pointer to the entire array
This example can be followed:

1
2
3
4
5
6
7
8
9
10
int main()
{
int a[],b[];
func(a,b);
//code
}
void func(int a1[],int b1[])
{
//code
}

In this example,the array pointer to a[] is a and any changes made to a1[] and b1[] will reflect in a[] and b[].
Last edited on
dsadf
Last edited on
In line 8-17

1
2
3
4
5
6
7
8
void PolarCoord(double ShiftX[], double ShiftY[], double PolVal[], double PolAngle[])
{
	
	int i = 0;
	PolVal[i] = sqrt(pow(ShiftX[i],2.0) + pow(ShiftY[i],2.0));
	PolAngle[i] = atan(ShiftY[i]/ShiftX[i]);

}


You don't need to return value for a void function.
 
}while ((CoorX == 0) & (CoorY == 0));


The = is an assignment operator
The == is the comparison operator

This happens to me everytime.I should have noticed it earlier.
Last edited on
noofa
Last edited on
adfa
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void PolarCoord(double ShiftX[], double ShiftY[], double PolVal[], double PolAngle[])
{
	
	int i = 0;
	PolVal[i] = sqrt(pow(ShiftX[i],2.0) + pow(ShiftY[i],2.0));
	PolAngle[i] = atan(ShiftY[i]/ShiftX[i]);
	

}
int main()
{
//code
double ShiftX[50];
double ShiftY[50];
double PolVal[50];
double PolAngle[50];
//code
PolarCoord(ShiftX, ShiftY, PolVal, PolAngle);
//code
}


I think you have actually done a call by reference without & symbol.We must wait for expert help.
By some googling I learnt that through default means we cannot pass the value of array by call by value method.Thus what you have did might be call by reference.
adfa
[/code]

Last edited on
Your logic should be something like:
1
2
3
4
5
6
7
8
9
10
11
12
for (int n = 0; n < 50; ++n)
{
	cout <<
		"Enter a pair of positive x, then y coordinates"
		" separated by spaces or ‘0 0’ to stop:" << endl;
	cin >> CoorX[n] >> CoorY[n];

	if (CoorX[n] == 0 && CoorY[n] == 0) // we'll talk about this
		break;

	// use the values
}


The problem with this is you can't check for zero this way with a floating point number. Floating point variables have a resolution called it's epsilon. You have to check if the value is within the epsilon for zero.
http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon

Fot doubles, the code can look like this:
1
2
3
4
5
6
7
8
9
bool isZero(float val)
{
    return -FLT_EPSILON < val  &&  val < FLT_EPSILON;
}

bool isZero(double val)
{
    return -DBL_EPSILON < val  &&  val < DBL_EPSILON;
}


So the loop becomes:
1
2
3
4
5
6
7
8
9
10
11
12
for (int n = 0; n < 50; ++n)
{
	cout <<
		"Enter a pair of positive x, then y coordinates"
		" separated by spaces or ‘0 0’ to stop:" << endl;
	cin >> CoorX[n] >> CoorY[n];

	if (isZero(CoorX[n])  &&  isZero(CoorY[n]))
		break;

	// use the values
}
Last edited on
jumpman530 wrote:
but I need to pass the two PolVal and PolAngle arrays by reference.

According to the OP:
jumpman530 wrote:
here's the instructions:
1) Make a method which takes as input parameters a pair of rectangular coordinates and sets as output parameters a pair of polar coordinates relative to the same point as the input rectangular coordinates.

You shouldn't be passing arrays to your function at all.


kbw wrote:
The problem with this is you can't check for zero this way with a floating point number.

Yes, you can. 0 is guaranteed to be exactly representable by any floating point type, and since we are going directly from input where the user is asked to input 0, there isn't much point in involving the epsilon value except to make things a little more complex. If one isn't working, the other won't work either. Something else is going on.
Topic archived. No new replies allowed.