Hi,
I'm trying to find the resultant of a given data using fstream. I made the program and everything and I believe its all correct however, when I try to run it, I'm getting a linker error saying "undefined reference to Resultant(const double...)" which I can't figure out how to fix it. Can you please help me spot the problem?
Thank you in advance.
This is the program:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
void Resultant(const double[], const double[], const double[], const double[], const int,
double&, double&, double&);
const double PI=acos(-1.0);
int main()
{
const int size = 200 ;
int moves = 0;
double Magnitude[size], X_axis[size], Y_axis[size], Z_axis[size];
double X_Resultant=0, Y_Resultant=0, Z_Resultant=0;
string choice, answer;
cout << "This program will calculate the Resultant Forces from a "
<< "selected data sheet.";
do
{
cout << "\n\nPlease type in the data sheet you want to be calculated?"
<< "\nEnter Force1 or Force2 : " ;
cin >> choice;
if (choice == "Force1" || "force1")
{
ifstream Data("Forces1.DAT");
if (Data.fail())
cout <<"\nFail To Open\nCheck File" << endl;
for ( int i=0; !Data.eof();i++)
{
Data >> Magnitude[i] >> X_axis[i] >> Y_axis[i] >> Z_axis[i];
moves++;
}
Data.close(); break;
}
else if (choice == "Force2" || "force1")
{
ifstream Data("Forces2.DAT");
if (Data.fail())
cout <<"\nFail To Open!\nCheck File" << endl;
for ( int i=0; !Data.eof();i++)
{
Data >> Magnitude[i] >> X_axis[i] >> Y_axis[i] >> Z_axis[i];
moves++;
}
Data.close(); break;
}
else {
cout << "\nERROR! Invalid Input! \nWould you like to"
<< " try again? Enter y or n : " ;
cin >> answer;
}
}
while (answer == "y" || answer == "Y");
Resultant(Magnitude, X_axis, Y_axis, Z_axis, moves, X_Resultant, Y_Resultant, Z_Resultant);
cout << setw(6) << X_Resultant << setw(6) << Y_Resultant << setw(6) << Z_Resultant;
system("pause");
return 0;
}
void Resultant(const double M[], const double X[], const double Y[], double Z[],
const int moves, double& Rx, double& Ry, double& Rz)
{
double Fx[moves], Fy[moves],Fz[moves];
for (int i=0; i<3; i++) // using 3 to test the program
{
Fx[i]= M[i]*cos(X[i]*180/PI);
Fy[i]= M[i]*cos(Y[i]*180/PI);
Fz[i]= M[i]*cos(Z[i]*180/PI);
}
for (int i=0; i<3; i++)
{
Rx += Fx[i];
Ry += Fy[i];
Rz += Fz[i];
}
}