So, I've been assigned to write a program that reads the wind-tunnel test data, that of which is called the "tunnel.dat" in my program, and then allows the user to enter a flight-path angle. If the angle entered is within the bounds of the data set, the program would need to do linear interpolation to compute the corresponding coefficient of lift, given by
f_b = f_a + ((b-a)/(a-c)) * (f_c - f_a)
The problem I'm having is that the program has successfully compiled, however the result isn't turning out as it should be. It's returning "The coefficient of lift is inf." where it should be a value given and computed from the arrays. The loop doesn't stop, or I mean that the program continues running even though it has returned "inf".
I'm not sure where my problem stands because my function seems to be correct, but any helpful input would be great, thank you :)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
const int N = 17;
int main()
{
double angle[N], clift[N]; //Declare and initialize objects.
double fl_ang, result;
ifstream fin("tunnel.dat");
if (fin.fail())
{ cerr << "Error opening input file." << endl;
exit(1); }
for (int k=0; k<17; k++) //Read and input data from file.
{ fin >> angle[k] >> clift[k];
cout << "Please enter the flight-path angle in degrees: ";
cin >> fl_ang;
if (fl_ang <= 21 && fl_ang >= -4)
{ if (fl_ang == angle[1])
{ k=2; }
else
{ k=1; }
do
{ result = clift[k-1] + ((fl_ang - angle[k-1])/(angle[k] -
angle[k-1])) * (clift[k] - clift[k-1]);
cout << "The coefficient of lift is " << result << "." << endl; }
while (angle[k] < fl_ang); }
else
{ cout << "Flight-path angle not in range." << endl; } }
fin.close(); //Close file stream.
return 0; }