# 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. ## 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: }

2. 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

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. actually ive gone trhu the code several times, and cant findt it, why would I otherwise post it here zacs7?

5. 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? */

}

}```

6. thanx every1, i was able to compile it