Need help with programming

I'm new to the forum, but I need some assistance with a program I am trying to write. I found a similar program, but it was using a one-dimensional array and my instructions need me to do it with a two-dimensional array.


A railroad track has a spur line that is a dead end. However, at the end of the line there is a railroad bumper that has been designed to stop a moving railroad car. At impact, the horizontal displacement in meters and the velocity in meters per second of the bumper as a function of time is given by:

displacement=4.219(e^(-1.58t)-e^(-6.32t))

velocity=26.67e^(-6.32t)-6.67e^(-1.58t)


DESCRIPTION OF VARIABLES:
NAME | TYPE | DESCRIPTION
-----------------------------------------------------------------------------
bumper | double | two-dimensional array of bumper impact values
time | int | time output in seconds
dis | int | displacement output in meters
velo | int | velocity output in meters per second
i | int | outer loop control variable
j | int | inner loop control variable
ndata | int | number of time data inputs
*******************************************************************************/

/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "e:\\personal\\school\\engr 200\\Exams\\Exam 3\\train.txt"
#define outputfile "e:\\personal\\school\\engr 200\\Exams\\Exam 3\\train_report.txt"

/* Main function */
int main(void)
{
/* Declare variables */
double bumper[51][3];
int time,dis,velo,i,j,ndata;
FILE *train,*train_report;

/* Open input file */
train = fopen(inputfile,"r");
train_report = fopen(outputfile,"w");

/* Verify input file and read input data */
if(train == NULL)
{
printf("\n\n\n\n ERROR OPENING INPUT FILE.");
printf("\n\n PROGRAM TERMINATED.\n\n\n");
return 0;
}
else
{
fscanf(train,"%i %i %i",&ndata);
for(i=0; i<=ndata-1; i++)
{
for(j=0; j<=ndata-1; j++)
fscanf(train,"%lf",&bumper[i][j]);
}
}
}
/* Compute displacement and velocity */
for(j=0; j<=ndata-1; j++)
{
for(i=0; i<-ndata-1; i++)
dis = 4.219 * (exp(-1.58*bumper[i][j]) - exp(-6.32*bumper[i][j]));
velo = (26.67 * exp(-6.32*bumper[i][j])) - (6.67 * exp(-1.58*bumper[i][j]));
}
I found a similar program, but it was using a one-dimensional array and my instructions need me to do it with a two-dimensional array.


Two dimensional array:
int twoDArray[10][10];

Access the array like this:

1
2
3
4
5
6
7
for(int k)
{
for(int p)
{
 twoDArray[k][p] // do something
}
}

Hope it helps
Topic archived. No new replies allowed.