Thread: Please help - Run time error

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    Please help - Run time error

    Hi i was wondering if some could help me quick with the run time error I have. I am quite new to programming and I have the course work that has to be in asap. Im sure my code is ok but im getting a run time error?

    code:
    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    float dx_dt(float x,float y);                                  //function declaration
    float dy_dt(float x,float y,float z);
    float dz_dt(float x,float y,float z);           
             
    int n=1,p=1,o=1;
    int i,day,month,option_file,option_1,option_2,z0;
    float a,b,c,t,x,y,z,step;
    float delta_t;
    
    float k1=0,k2=0,l1=0,l2=0,m1=0,m2=0;                            //initalising values
    char fname[20], again;                                     
     
    int m_num_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};     //month array
    int midx;                                                       //month index
    
                            
    int main()   {
        
     again='Y';                                                     //Initialise loop to repeat
     while (again == 'Y'){                                          //programe
     n=1;
    
            printf("******************** THE UNIVERSITY OF NOTTINGHAM ********************\n");
            printf("******* NUMERICAL CALCULATION SOLUTIONS TO THE LORENZ EQUATION *******\n");
            printf("****************** VIA THE IMPROVED EULER METHOD *********************\n");
            printf("************************ by Craig Barker *****************************\n");
    
    
    FILE*POINT;                                                    //Declaring a file pointer
    
     
    
            while (n==1)                                           //Loop so values can be changed
               {  
                    printf("\nPlease input the following values:\n\n"); //Vaules inputted are 
                    printf("\nPantal Number:");                         //scanned in
                    scanf("%f", &a);
    
                    printf("\nReynolds Number:");
                    scanf("%f", &b);
    
                    printf("\nBox Ratio:");
                    scanf("%f", &c); 
                  
                    printf("\nz value:");
                    scanf("%d", &z0);
    
                    printf("\nTime Peroid (0<t100):");
                    scanf("%f", &t); 
            
                            while (t<=0||t>99)                     //Error check that time period
                            {                                      //is in its limits
                            printf ("INVALID - Please re-input Time Period (0<t<100)");
                            scanf ("%f", &t); 
                            }
            
           month=0;
                            while((month < 1) || (month > 12))     //loop to make sure month
                            {                                      //is in limits
                            printf("\nMonth of your birth:");
                            scanf("%d", &month);
                            midx = (int)month;
                            }
           
            day=0;                                                 //checks day to be valid within 
                                                                   //selected month via an array
                            while((day < 1) || (day > m_num_days[midx-1])) 
                            {
                            printf("\nDay of your birth [1-%d]:",m_num_days[midx-1]);
                            scanf("%d", &day);
                            day = (int)day;
                            }
            
                    printf("\nStep Size:");
                    scanf("%f", &step);  
       
                   
                    printf("\n\nBelow are your chosen values");    //prints values to screen    
                    printf("\n Prantl Number = %f",a);        
                    printf("\n Reynold's Number = %f",b);        
                    printf("\n Box Ratio = %f",c);
                    printf("\n z0 = %d",z0);        
                    printf("\n Time Period = %f",t);
                    printf("\n Day = %d",day);
                    printf("\n Year = %d",month);
                    printf("\n Step Size = %f",step);       
            
                    o=1; 
                            while (o==1)                           //loop so values can be changed
                            {
                            printf("\n\nWould you like to change these numbers?");
                            printf("\n [1] - YES");
                            printf("\n [2] - NO");
                            printf("\n\n Choice =");  
                            scanf ("%d", &option_1);
            
                                    switch (option_1)              //Change values menu
                                    {
                                    case 1:                        //Loop back to the top
                                            n=1;
                                            o=2;
                                            break;  
                    
                                    case 2:                        //breaks out of loop and
                                            n=2;                   //carries on
                                            o=2;
                                            break;
                    
                                    default:                       //invalid entry
                                            n=2;
                                            o=1; 
                                            printf ("\n\nINVALID - Please choose again"); 
                                    }
                            }
               }
                        
             printf ("\n\n[1] - USE AN EXISTING FILE\n");          //Where would the file like to 
             printf ("[2] - CREATE A NEW FILE\n");                 //be saved? menu
             printf("\n\n Choice =");  
             scanf ("%d",&option_file);
               
                    switch (option_file)
                    {
                    case 1:                                        //asks for a valid filename,
                            printf ("\nPlease insert the existing file name");     //max 15 char
                            printf ("\n\nFile Name:");
                            scanf ("%s", fname);
                    
                            POINT=fopen(fname, "a");               //creates the file
                            break;
                    
                    case 2:                                        //asks for a valid file name
                            printf ("please enter the new file name");             //max 15 char
                            printf ("\n\nFile Name:");
                            scanf("%s", fname);
                    
                            POINT=fopen(fname,"a");                //creates the file
                            break;
                    
                     default:                                      //invalid entry
              
                            printf("\nplease try again");
                    }
                
                 
                while (p==1)                                       //confirm you would like to 
                {                                                  //write values to the file
                    printf ("\nWould you like to write the data inputted to the the chosen file");
                    printf ("\n[1] - Yes");
                    printf ("\n[2] - No");
                    printf("\n\n Choice =");
                    scanf ("%d", &option_2);
                    getc(stdin);                                   //debug scanf
             
                    switch (option_2)
                    {
                            case 1:                               //writes values to file
                                    fprintf (POINT,"\n\nPrantal Number = %f", a);
                                    fprintf (POINT,"\nReynolds Number = %f", b);
                                    fprintf (POINT,"\nBox Ratio = %f", c);
                                    fprintf (POINT,"\nz = %d", z0);
                                    fprintf (POINT,"\nTime Period = %f", t);
                                    fprintf (POINT,"\nmonth = %d", month);
                                    fprintf (POINT,"\nDay = %d\n", day);
                                    p=2;
                                    break;
                    
                            case 2:                                //does not write values to file
                                    printf ("\nNo data has been written to the file!");
                                    p=2;
                                    break;
                    
                            default:                               //invalid entry
                                    p=1;
                                    printf ("\n\nINVALID - Please try again!");
                    }  
                }
              
            x=day;                                                 //sets variables
            y=month;                                               
            z=z0;
            delta_t=(t/step);                                      //calcs step size 
              
            fprintf(POINT,"t,x,y,z\n");                            //writes headers to file
              
                    for(i=0; i<=step; i++)                         //loop to keep inputting
                    {                                              //new vaiables.
                            k1 = delta_t*dx_dt(x,y);               //Receives value from function
                            k2 = delta_t*dx_dt(x+k1,y);            // and calulates k,l and m values
                
                            l1 = delta_t*dy_dt(x,y,z);
                            l2 = delta_t*dy_dt(x,y+l1,z);
                
                            m1 = delta_t*dz_dt(x,y,z) ;
                            m2 = delta_t*dz_dt(x,y,z+m1);
                              
                            x=x+(0.5*(k1+k2));                     //Improve value of x
                            y=y+(0.5*(l1+l2));                     //Improve value of y
                            z=z+(0.5*(m1+m2));                     //Improve value of z
              
                            fprintf(POINT,"%d,%f,%f,%f\n",i,x,y,z);//write the calculated values                    
                    }        
              
                                                                   
            fclose(POINT);                                         //closes the file
              
            printf ("\n\nDATA TRANSFER COMPLETE TO %s",fname);     //confirm tranfer
            printf ("\n\nWould you like to start the programe again? Y/N:");
            scanf("%c",&again);                                    //option to run program again
            getc(stdin);
                              
            }
            return 0;        
            }    
              
                    float dx_dt()                                  //functions to calculate dxdt
                    { return (a*(y-x));}                           //dydt and dzdt
                    
                    float dy_dt()
                    { return ((x*(b-z))-y);}   
              
                    float dz_dt()
                    { return ((x*y)-(c*z));}
    Thanks in adavnce for the quick replies it going to to get me out of a creek.


    Craig

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Code:
    switch (option_file)
                    {
                    case 1:                                        //asks for a valid filename,
                            printf ("\nPlease insert the existing file name");     //max 15 char
                            printf ("\n\nFile Name:");
                            scanf ("%s", fname);
                    
                            POINT=fopen(fname, "a");               //creates the file
                            break;
                    
                    case 2:                                        //asks for a valid file name
                            printf ("please enter the new file name");             //max 15 char
                            printf ("\n\nFile Name:");
                            scanf("%s", fname);
                    
                            POINT=fopen(fname,"a");                //creates the file
                            break;
                    
                     default:                                      //invalid entry
              
                            printf("\nplease try again");
                    }

    Check out the scanf statements here. I'm not sure if that's your only problem, but it's a start.

    Oh, and for future reference, those errors are usually caused by this problem.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    3
    The run time error says (call to missing routin: _dx_dt(float,float)

    I dont knonw it that helps becuase the scanf's are fine to my knowledge

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Are your dx_dt() function definitions in the same source file?

    Also, which OS/Compiler are you using (noting that there are some very bad compilers out there).
    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.

  5. #5
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Oh ........, that was an array, sorry mate.


    [EDIT]

    Oh, automatic censoring, very cool.

    [/EDIT]
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    3
    The complier im using is salford C.

    I have declared the functions at the top of the source file and the actual function are below my main program. So yes they are in the same source file

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > float dx_dt(float x,float y);
    This....

    > float dx_dt()
    Must match this
    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. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM