I need help with adding arrays/vectors

This is what I have. Everything works the way it is suppose to but the addition of the arrays/vectors are not right. The DOS prompt is at the bottom with an explanation of what I need help with. Thank you.


#include <iostream>
using namespace std;

int main()
{
const int size = 100;
int i;
double vector1[size];
double vector2[size];
double vector3[size];
int x;
double result[size];

cout << "Enter size of vector [1-100]: ";
cin >> x;

if(x > size)
{
exit(0);
}
for (i = 0; i < x;i++)
{
cout << "Enter the component data: ";
cin >> vector1[i];
}
cout <<" "<< endl;
for (i = 0;i < x;i++)
{
cout << vector1[i] << " \n";
}
if(x > size)
{
exit(0);
}
for (i = 0; i < x;i++)
{
cout << "Enter the component data: ";
cin >> vector2[i];
}
cout <<" "<< endl;
for (i = 0;i < x;i++)
{
cout << vector2[i] << " \n";
}


if(x > size)
{
exit(0);
}
for (i = 0; i < x;i++)
{
cout << "Enter the component data: ";
cin >> vector3[i];
}
cout <<" "<< endl;
for (i = 0;i < x;i++)
{
cout << vector3[i] << " \n";
}
cout << "\n";
for(i = 0; i < x; i++)
{
cout << vector1[i] << "\t " << vector2[i] << "\t " << vector3[i] << endl;
}
cout << "Result vector (addition): \n";
for(i = 0; i < x; i++)
{
result[i] = vector1[i] + vector2[i] + vector3[i];
cout << result[i];
}
system("pause");
return 0;
}








Enter size of vector [1-100]: 3
Enter the component data: 1
Enter the component data: 2
Enter the component data: 3

1
2
3
Enter the component data: 1
Enter the component data: 2
Enter the component data: 3

1
2
3
Enter the component data: 1
Enter the component data: 2
Enter the component data: 3

1
2
3

1 1 1
2 2 2
3 3 3
Result vector (addition):
369Press any key to continue . . .

***I need to add the components in each column. Instead of getting 3,6,9 as the result.... I need it to add up to 6, 6, 6,. These are just arbitrary numbers I made up.
Nevermind... I got it. I changed the end of the it from:

result[i] = vector1[i] + vector2[i] + vector3[i];
cout << result[i];
}
system("pause");
return 0;
}

to.....

result1 += vector1[i];
result2 += vector2[i];
result3 += vector3[i];
}
cout << result1 << " \t" << result2 << " \t" << result3 <<endl;
cout << "\n\n";

system("pause");
return 0;
}
Topic archived. No new replies allowed.