So I'm trying to let the user supply the elements of two vectors but using a while (cin >> ..)
would crash my program. Here is what I have so far:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
size_t size = 4; int i;
vector<int> product;
vector<int> v1;
vector<int> v2;
int input, input2;
cout << "Enter values for first vector: ";
while (cin >> input) {
v1.push_back(input);
}
cout << "Enter values for second vector: ";
while (cin >> input2) {
v2.push_back(input2);
}
int result = 0;
if (size >= 1) {
result += v1[0]*v2[0];
for (int i = 1; i < size; ++i)
result -= v1[i]*v2[i];
}
cout << result << endl;
return 0;
}
User has to input N elements for the first vector and another N elements for the second vector. However, I cannot skip the usage of reading till EOF because I don't know how many elements the users want to store in each vector.