multiplying two vectors

here is the thing i want to create two vectors and through "FOR" insert the values and then multiply them both with each other.

that is my try pls help
int a, b;
vector<int>numbers1;
vector<int>numbers2;

for(int i=1;i<5;i++)
{
cin >> a;
numbers1.push_back(a);

}

for (int j = 1; j<5; j++)
{
cin >> b;
numbers2.push_back(b);

}

for(int i=0;i>100;i++)
{
cout << setw(3) << numbers1[i] * numbers2[i];

}
cout << endl;
You only fill the first 4 positions in both vectors with numbers but then you try to multiply the numbers in the vectors through the first 100 positions but there are only numbers in the first 4. Use something like:

1
2
3
4
5
6
7
int size = numbers1.size();

for(int i=0;i<size;i++)
{
cout << setw(3) << numbers1[i] * numbers2[i];

}
Last edited on
i know but the positions don't mean to much the problem is i need the numbers i tipped in to multiply with each other
i know there has to be a for in for loop to multiply them like in making an multiplication table but how?????????????????? i'm getting mand
I don't see exactly what your problem is but here is my version which does work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include <iomanip>
#include <vector>
using namespace std;



int main()
{
	int a, b, size;

	vector<int>numbers1;
	vector<int>numbers2;

	//fill first vector
	cout << "Enter 5 numbers in the first vector" << endl;
	for (int count = 0; count<5; count++)
	{
		cin >> a;
		numbers1.push_back(a);
	}

	//fill second vector
	cout << "Enter 5 numbers in the second vector" << endl;
	for (int count = 0; count<5; count++)
	{
		cin >> b;
		numbers2.push_back(b);

	}

	//check vecot sizes are still the same
	if (numbers1.size() == numbers2.size())
	{
		//find size of vectors
		size = numbers1.size();

		//multiplie and output each corrisponding number
		for (int i = 0; i < size; i++)
		{
			cout << setw(3) << numbers1[i] * numbers2[i] << endl;

		}
	}

	else
	{
		cout << "Error" << endl;
	}
	cout << "\n";
	return 0;
}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa it work's you saved my I almost lost my mind (just kidding hahaha :D) thx very very much :D
Topic archived. No new replies allowed.