Urgent! cant find errors

This is a discussion on Urgent! cant find errors within the C Programming forums, part of the General Programming Boards category; Hi Hope u can take ur time to help, i have to hand in a program within a few hours, ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    3

    Urgent! cant find errors

    Hi
    Hope u can take ur time to help, i have to hand in a program within a few hours, ive written the code, but can't compile it

    PROBLEM:
    Problem: Consider a first order ODEs that describe the radioactive decay process:
    u˙ + u = 0 and u(t = 0) = u0, (4)
    Here, u(t) represent the flux of neutrons and is a radioactive decay constant. Solve this equation
    using Euler’s method (3) to obtain a time profile of the function u(t). Following the Euler’s
    solution, the difference equation for u at step n (time step tn):
    un+1 = un
    − unt. (5)
    Your program should accept initial value u0 and as command line arguments. These should be
    larger than zero (validate the input!). You should then setup a loop where you will advance your
    solution in time using formula (5) (don’t forget to increment the time). The solution should be
    written to the external file with the name given by idxxx prog4A.out where idxxx is your ITS
    user id (ids start with ph for physics, cs for computer science, etc...). The file should contain two
    columns separated by a single space: time t followed by u(t). You should consider following values
    of parameters: u0 = 1.0, = 0.1 and t = 0.01 as a test. Then try other values (what happens
    if >> t?). The number of points in your file should not be too large (no more than 10000

    AND HERE IS MY CODE
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    /* Function main() is defined so that
       it can accept command line arguments */
       
    int main(int argc, char* argv[])
    {
         double  u_0, lambda, delta_t;
    	 int i, n;
    	 float u[5000];
    	 float t[5000];
    	 
    	 FILE *output;
    	 output = fopen("xxx_prog4a.out", "w")
    
         /* Check if two arguments were entered with
            the program name. */
         if(argc < 3)
         {        printf("Two arguments needed!\n");
            exit(EXIT_FAILURE);
         }
         else
         {
            /* Remember, all arguments are stored as
               strings so we have to convert them to
               numbers using sscanf */
            sscanf(argv[1], "&#37;lg", &u_o);
            sscanf(argv[2], "%lg", &lambda);
    		u[0] = u_o;
    		t[0] = 0;
    		delta_t = 0.01;
    		N = 4500;
    		for (i = 0; i<N; i++)
    		{
    		t[i+1] = t[i] + delta_t;
    		u[i+1] = u[i] - (u[i] * lambda * delta_t);
    		fprintf(xxx_prog4a,"4.2%lf\t4.2%lf\n",t[i],u[i]);
    		}
    		fclose(output);
    		
    		return(o);
    		
    	}
    		
    		}
    and the errors are as following

    "aab.c", line 20: syntax error before or at: if
    "aab.c", line 24: syntax error before or at: else
    "aab.c", line 41: warning: function prototype parameters must have types
    "aab.c", line 41: warning: old-style declaration or incorrect type for: fclose
    "aab.c", line 43: syntax error before or at: return
    "aab.c", line 43: warning: old-style declaration or incorrect type for: o
    "aab.c", line 45: syntax error before or at: }
    Last edited by sssouljah; 11-21-2007 at 04:16 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    output = fopen("xxx_prog4a.out", "w")
    Missing a semi-colon.

    I think every single of the remaining errors are related to that.
    [1]

    Code:
    return(o);
    Do you mean the letter o here or the number 0 - there is no variable by the name of the letter 'o', so the compiler complains.

    Your placement of braces is a bit "Here and there" - perhaps re-indenting the code would help to see what's going on too.

    [1] The compiler gets lost when it's missing certain things, like semi-colons or braces. It's a little bit like if I give you a long list of directions, which start by "Turn right off Big Road when you get to the Big Tree on the right-hand side of the road" - if someone has cut down the big tree, then you'd be turning right at the wrong place, and from there on the rest of the instructions would of course be meaningless, because you took the first turning wrong, and you end up somewhere completely different [and at some point, the directions probably make no sense, such as you get to a dead-end or some such].

    --
    Mats
    Last edited by matsp; 11-21-2007 at 04:24 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Read the rules,

    2. Don't ask people to do all your work for you, See the announcement on Homework below; for more info about what is considered acceptable.
    Some issues of netiquette to particularly note are:
    1. Don't use all caps
    2. Use descriptive subject lines
    3. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
    No one is going to go through your homework and pick out errors, that's your job. If you wrote that entire piece of code by yourself you should be able to find the errors. Hell it even gives you the line numbers.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    actually ive gone trhu the code several times, and cant findt it, why would I otherwise post it here zacs7?

  5. #5
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    /* Function main() is defined so that
       it can accept command line arguments */
       
    int main(int argc, char* argv[])
    {
         double  u_0, lambda, delta_t;
    	 int i, n;
    	 float u[5000];
    	 float t[5000];
    	 
    	 FILE *output;
    	 output = fopen("xxx_prog4a.out", "w") /* missing ; */
    	 
         /* Check if two arguments were entered with
            the program name. */
         if(argc < 3)
         {
            printf("Two arguments needed!\n");
            exit(EXIT_FAILURE);
         }
         else
         {
            /* Remember, all arguments are stored as
               strings so we have to convert them to
               numbers using sscanf */
            sscanf(argv[1], "&#37;lg", &u_o);  /* change o to 0 */
            sscanf(argv[2], "%lg", &lambda);
    		u[0] = u_o; /* change o to 0 */
    		t[0] = 0;
    		delta_t = 0.01;
    		N = 4500;    /* change N to n */
    		for (i = 0; i<N; i++) /* change N to n */
    		{
    		t[i+1] = t[i] + delta_t;
    		u[i+1] = u[i] - (u[i] * lambda * delta_t);
    		fprintf(xxx_prog4a,"4.2%lf\t4.2%lf\n",t[i],u[i]); /* change xxx_prog4a for output that is the file handler */
    		}
    		fclose(output);
    		
    		return(o); /* where's o declared? */
    		
    	}
    		
    		}
    Last edited by Aia; 11-21-2007 at 04:43 PM.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    thanx every1, i was able to compile it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  3. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM
  4. cant find the errors.
    By sscook69 in forum C++ Programming
    Replies: 2
    Last Post: 09-10-2001, 05:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21