
Help with c programming please
Hello all this is my first post.
I'm writing a program in 'c' using lcc win32.
The program is to perform eulers calculation and store answers in arrays.
The program is to use pointers, arrays and functions.
This is the start of my program any help or tips are appreciated.
#include <stdio.h>
#include <math.h>
void calculation (float Y[], float X[], int i, float step_interval)
{
i = 0;
Y[0] = 0;
Y[0] = 1;
for (i=0; i<=step_interval; i++)
{
Y[i+1] = Y[i] + (step_interval) * (X[i] * (exp, (X[i])));
}
for (i = 0; i <= step_interval; i++)
{
printf ("%f, %f", Y[i], X[i]);
}
}
void main()
{
float X, Y, step_size, time_interval;
int num, exp, sum, i;
printf("\n Please enter the intial conditions of 'x': ");
scanf("%f", &X);
printf("\n Please enter the intial conditions of 'y': ");
scanf("%f", &Y);
printf("\n Please enter the step size (h): ");
scanf("%f", &step_size);
printf("\n Please enter the time interval: ");
scanf("%f", &time_interval);
calculation =(X, Y, &step_size, &time_interval);
printf("\n The value of sum = %f\n\n",calculation);
}
Thank You

Have you compiled the program? Did the compiler tell you anything? Did you understand what the compiler told you?
(The compiler is smarter than me; use as much information from him as possible, and get back to us if you need help getting to the next step.)

Cheers for reply
made some changes.
Still problems with:
Y[i+1] = calculation(X, Y, step_size, time_interval);
Comments: The object is to perform eulers equation for the particular
solution of (x exp x).
Eulers equation is y + h (x exp x)
h = number of step sizes
y and x increment by 1 each step size until the user defined
time interval is reached.
Errors:
type error: pointer expexted
type error in arguement 1 to 'calculation'; found 'float' expected to pointer to float.
type error in arguement 2 to 'calculation'; found 'float' expected to pointer to float.
operands of = have illegal types 'float' and 'void'

I'm just guessing, since you didn't tell us what changes you made, but:
You define calculation() with arguments
float X[], float Y[], etc.
Now, the compiler sees these as
float *X, float *Y, etc.
Thus the message about "expecting pointer to float".
Your original post showed that you called calculation() with X and Y as arguments, where X and Y were declared as type float in main().
Does this help?
Dave
Popular pages
Recent additions