Thread: Flight Recorder Data

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Flight Recorder Data

    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.

    insert
    Code:
    #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);
    }}

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    FYI, in the future, please post anything that has to do with C in the C forum, not the C++ forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    First, indentation!
    Code:
    #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);
      }
    }
    line 19 - when do you assign k for this comparison to pass/fail at some point.
    line 21 - you need to express it as a <= b && b <= c
    line 23 - stops lines 24 and 25 from ever happening
    line 24 - read up on printf - you don't need & when printing values.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IOCCC Flight Simulator
    By Tonto in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-18-2009, 10:06 PM
  2. Monitor Recorder
    By CrazyShellsSlam in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-25-2007, 07:01 PM
  3. Decent recorder?
    By Shadow in forum Tech Board
    Replies: 0
    Last Post: 05-17-2004, 02:08 AM
  4. Sound Recorder work...Advice me.
    By loobian in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-14-2003, 09:58 PM