I have to write a program that will work with a data file and will be able to read a time a give you the height.
Flight.txt is
0.0 0.0
1.0 7.9
2.0 15.7
3.0 23.3
5.0 38.7
10.0 72.3
20.0 128.9
30.0 168.3
40.0 192.5
50.0 200.1
60.0 192.8
70.0 168.3
80.0 128.4
90.0 72.7
ENG40_Flight.cpp
so far i have this but it ask me to enter a time but it wont give me a height back.
insertCode:#include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { int k; double time, height, time1, height1, time2, height2; FILE*mydata; mydata = fopen("F:\\Flight.txt", "r"); { k = fscanf(mydata, "%lf %lf", &time1, &height2); } { printf("Enter a time\n"); scanf("%lf", &time); while (k==2) { fscanf(mydata, "%lf %lf", &time2, &height2); if (time1 =< time =< time2) { height = height1 + ((time - time1) / (time2 - time1)) - (height2 - height1); return height; printf("The height is %lf\n", &height); break; } else { time1=time2; height1=height2; } } fclose(mydata); system("PAUSE"); return(0); }}



LinkBack URL
About LinkBacks



