Resultant Forces program stuck on adding components

#include<iostream>
#include<fstream>
#include<iomanip>
#include<cmath>

using namespace std;

const double pi = 3.14159;
//***********************************************************
void COMPONENTS (double, double, double, double, double&, double&, double&);
//***********************************************************
int main()
{

int counter = 1;
double magnitude, theta_x, theta_y, theta_z, x_component, y_component, z_component,
x_result, y_result, z_result;


ifstream infile ("C:FORCES.txt");
ofstream outfile ("C:ANSWER3.txt");


if (infile.fail())
{
cout << "Error. Unable to read file" << endl;
return 0;
}

else
{

outfile << "Name of input data file: FORCES3.txt" << endl;
outfile << "\n";
outfile << "\n" << setw(8) << "x-components(lb) " << "y-components(lb) " << z-components(lb) "<< endl;
outfile << endl;

while ( counter < 4 && !infile.eof())
{
infile >> magnitude >> theta_x >> theta_y >> theta_z;


COMPONENTS(magnitude, theta_x, theta_y, theta_z, x_component, y_component, z_component);

outfile << showpoint << " " << x_component <<" "<< y_component <<" "<< z_component;
outfile << endl;

x_result += x_component;
y_result += y_component;
z_result += z_component;

counter++;
//outfile << x_result;
}

outfile << "---------------- ------------- ------------------ ";
outfile << "\n";
outfile << "\n";
outfile << "Rx = " << x_result << " Ry = " << y_result << " Rz = " << z_result;
infile.close();

}





return 0;

}
void COMPONENTS (double mag, double x, double y , double z, double& F_x, double& F_y, double& F_z)
{

F_x = mag * cos(x*pi/180);
F_y = mag * cos(y*pi/180);
F_z = mag * cos(z*pi/180);

return;

}

[/code]


Then enlarged part is what I'm having trouble with.
Just to let you know, I'm not even half finished with this program, but I can't get past this one error.
I'm trying to add up the components, but this is what I get in my outputfile:
-----------------------------------------------------------------------------------------------------------------
C:ANSWER3.txt

Name of input data file: FORCES3.txt


x-components(lb) y-components(lb) z-components(lb)

76.6045 50.0001 40.4025
151.554 59.8537 63.8252
33.6466 83.5625 93.7346
---------------- ----------------- ----------------

Rx = 1.09232e+265 Ry = -1.#QNAN Rz = 197.962


---------------------------------------------------------------------------------------------------------------

Here is my input file:
C:FORCES.txt

100 40 60 66.17
175 30 70 68.61
130 75 50 43.86
---------------------------------------------------------------------------------------------------------------


Rz is correct, but obviously Rx and Ry are not.
You don't initialize x_result, y_result and z_result. Initialize those to zero at the start and you should be okay.
I figured that out earlier, and it's all coming together! Thanks!
Topic archived. No new replies allowed.