I am working on this function where I have to take two arrays and perform a func
ID: 3547471 • Letter: I
Question
I am working on this function where I have to take two arrays and perform a function with the results going into a third array.
This is a short version of what I have.
#include <iostream> //pre-processor directs - iostream talks to screen
#include <fstream> //pre-processor directs - allows accessing and inputing to data files
#include <string> //pre-processor directs - enables string class functions
#include <cmath> //pre-processor directs - allows math functions
const int size=30;
using namespace std; //introduces namespace std
void velcFts (double, double, double);
int main ()
{
int i=0;
string filename;
ifstream inFile;
string car, date, driver;
double time[size], dist[size], velcf[size];
inFile.open("CAR1a.txt");
if (!inFile.good())
{
cout<<"Could not open file"<<endl;
system ("pause");
return 1;
}
while (!inFile.eof()) //Reads the rest of the file into arrays time[i] and dist[i]
{
inFile>>time[i]>>dist[i];
velcFts (time[size], dist[size], velcf[size]);
cout<<time[i]<<", "<<dist[i]<<", "<<velcf[i]<<","<<endl;
i++;
}
inFile.close();
system("pause");
return 0;
}
//******************Velocity (ft/s) function definition*************************
void velcFts (double time[size], double dist[size], double velcf[size])
{
for (int i=0;i<=size;i++) //initiates, defines and sets counter
{
velcf[i] = (dist[i+1]-dist[i])/(time[i+1]-time[i]);
}
}
When I try to run the program i get the following error- [Linker error] undefined reference to 'velcFts(double, double, double)' and Id returned 1 exit status
What am I doing wrong here. I know that it is probibly something simple that I am overlooking. Help with an explination would be greatly appreciated.
Explanation / Answer
Your prototype is conflicting your function.
void velcFts (double, double, double);
asks for 3 doubles however in your function
void velcFts (double time[size], double dist[size], double velcf[size])
{
for (int i=0;i<=size;i++) //initiates, defines and sets counter
{
velcf[i] = (dist[i+1]-dist[i])/(time[i+1]-time[i]);
}
}
It ends up asking for double arrays.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.