I wrote this simple program and I am trying to add up all the elements of one array into one element of another array but this does not seem to work. As shown below I am using this function: dx[y]+= fx [y];
Any suggestions?
# include <iostream>
# include <cmath>
using namespace std;
double fx [4], dx [4];
int y;
int main ()
{
{ fx [0] = -2.123; fx [3] = 4.2233;
cout<< abs (fx [0]) <<endl;
cout << fx [1]<< endl;
cout <<fx [2]<< endl;
cout << fx [3] << endl;
cout << pow (fx [3], 3)<< endl;
cout << sqrt (81) << endl;
for (y = 0; y < 4; y++)
{
dx[y]+= fx [y];
cout << dx [y]<<endl;
}
You have to set all your variables to 0 manually, The thing is when you don’t you will get a number that is left in the memory by another program. Not a very good example