Ok, so here's the program:
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
double linear (double, double );
int main ()
{
double altit[17], temp[17], pres[17], alt;
ifstream input ("atmosphere.txt");
cout <<"please enter an altitude: ";
cin >> alt;
for (int i=0; i<17; i++)
{
input >> altit[i] >> temp[i] >> pres[i];
}
int base = linear(altit[], alt);
double x1 = altit[base], x2 = altit[base++], y1 = temp[base], y2 = temp[base++], z1 = pres[base], z2 = pres[base++];
double y = y1+(((y2-y1)/(x2-x1))*(alt-x1));
double z = y1+(((y2-y1)/(x2-x1))*(alt-x1));
cout <<" x y z\n\n";
cout << alt <<" "<<y<<" "<<z;
system("pause");
return(0);
}
double linear (double array[], double alt)
{
for (int j=0; j<17; j++)
{
if (alt >array[j] && alt<array[j++])
{
return j;
}
}
return 0; // error case
}
I'm stumped, so any help will be great. Thanks!

New Topic/Question
Reply
MultiQuote





|