Hello, let me start by saying that I am extremely inexperienced and confused, so please bear with me. I am attempting to write a program in which I am given a data file with up to 100 pairs of (x,y) coordinates, and I must perform various calculations. One of these calculations is to "find the average of only the negative y-values" in the given set of data. I have created a loop which collects all of the x-values and y-values and placed them into arrays, so that I may use those arrays to perform all of the necessary calculations. This is what I have for a loop to calculate the needed value, although it is wrong.
The following describe the objects that I have used.
int i // Integer used in array.
int N // Total number of data pairs. (This is given in data file)
float x[100] // Array of x-values.
float y[100] // Array of y-values.
float sumny // Sum of only the negative y-values.
float avgny // Average of only the negative y-values.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for (i=0; i<N; i++)
{
if (y[i] < 0)
{
sumny = sumny + y[i];
}
else
{
sumny = sumny;
}
avgny = sumny / i;
}
|
Any help would be appreciated greatly. Thanks for your time and effort with this, and hope you have a great day.