I've written a program that reads file data into 2 separate arrays.

Each line in the file contains 2 values: a and f(a)

So there are 2 arrays: first one is a, second one for f(a).

(In the question and code, array containing a is angle[N], and array containing f(a) is coeff[N].)

The user enters value b.

If b = a for any value in the first array, then no calculation is required, f(b) = f(a) and we print the element in the 2nd array containing with the same index as first array with b=a.

Else, we need 2 values from array containing a to interpolate f(b). One is larger than b, one smaller. And the corresponding f(a) and f(c) are used to get f(b)

Formula for interpolation:

f(b) = f(a) + ((b-a)/(c-a))*(f(c) - f(a));

I'm stuck on how to make it if b=a, then break out of the loop and just print f(a) andnotprint the f(b) computed with the formula. I tried using break and setting the counter k to the last count, but it still computes f(b) using the interpolation formula for all of the values accumulatedbeforeit had hit the point for b=a. (There's 2 values printed: one from the if statement where a=b, and one from the interpolation. It's confusing to the reader, the second one is also wrong.)

So I've resorted to the dumb "Ignore statement below" warning for the case b=a as to not confuse the user.

Any hints would be appreciated.

Thank you.Code:/* Use linear interpolation to compute the coefficient of lift for flight-path angles. */ /* If user input is within bounds of file. */ #include <stdio.h> #include <math.h> #include <stdlib.h> #define FILENAME "flight-path.txt" #define PI 3.1415926535 #define N 17 int main(void) { /* Declare variables. */ double a, f_a, b, f_b, c, f_c; double angle[N], coeff[N]; int k; FILE *flight; /* Open file. */ flight = fopen(FILENAME,"r"); if (flight == NULL) printf("Error opening input file. \n"); else { /* Read data into two 1-D arrays. */ for (k=0;k<N;k++) fscanf(flight,"%lf %lf",&angle[k],&coeff[k]); /* Get user input from keyboard. */ printf("Enter new flight-path angle for interpolation \n" "(between -4 and 21 degrees): \n"); scanf("%lf",&b); printf(" b = %f \n",b); a = -4; c = 21; f_a = -0.182; f_c = 1.059; /* Find f_a, a, f_c, c in arrays. */ for (k=0;k<=N-1;k++) { if (angle[k] == b) { printf("Data found in file: coefficient of lift at angle %f is %f. \n" "Ignore statement below. \n",b,coeff[k]); k = N-1; } if ((angle[k] <= b) && (angle[k] >= a)) { a = angle[k]; f_a = coeff[k]; } if ((angle[k] >= b) && (angle[k] <= c)) { c = angle[k]; f_c = coeff[k]; } } /* Use linear interpolation to compute f_b. */ f_b = f_a + ((b-a)/(c-a))*(f_c - f_a); b = b*PI/180; /* Print new coefficient of lift. */ printf("New coefficient of lift at flight-path angle of %f radians: %f \n",b,f_b); } /* Exit Program. */ system("pause"); return 0; }

agrees : Is me, few years ago. google earth near 44° 8'55.36"N 73°52'39.33"W Adirondack park, NY. USA. with 24 hr. flu setting in.