Array confusion

I'm writing a code that reads data from an input file and uses it to calculate the acceleration of a rocket. The data I have shows time and velocity where the rocket during the first couple of seconds (0, 0.1, 0.2) is at a stand still and the velocity remains at 0. I'm new to using arrays and am trying to figure out if it's possible to use only one array in a loop to calculate acceleration. I'm having difficulty because the first few moments have a time of 0 which would lead to division by zero. My code is empty of arrays but I'll include it just in case anyone would like to take a look. I have a few prototypes included but those were given by my instructor to be used but I've yet to effectively use them in the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstdlib>

//Data types
double velocity, time;
const int LINE_LENGTH(50);
char cstring1[LINE_LENGTH];
using namespace std;

//Prototype
bool AccelerationArray(int n, double time[], double velocity[], double acceleration[]);
void displayTable(int n, double time[], double velocity[], double acceleration[]);

//Main code
int main(){
    cout.setf(ios::fixed);
    cout.precision(3);
    time = 0;
    ifstream input1;
    input1.open("rocketVelocityData.txt");
    input1.getline(cstring1, LINE_LENGTH);

//Looping code
if (!input1.fail())
{
    cout << "Number " <<" Time(s) " << " Velocity(m/s) " << " Acceleration(m/s^2) " << endl;
    {
        while(time<=65.7){
            for(int n = 0 ; n <= 172; n++)
            {
            input1 >> time >> velocity;
            cout <<setw(3)<< n <<setw(11)<< time <<setw(11)<<velocity<<endl;}
    }
    }
}
else{
            cout << "Could Not Open File" << endl;}
}
Topic archived. No new replies allowed.