I have this problem where I can't replace elements for 'numVect' through a function 'InputNumbers()' using user input. I tried to create a new vector in the function, and then define it as 'numVect' but no success.
#include <iostream>
#include <vector>
using namespace std;
vector <int> InputNumbers(vector <int> numVect) {
vector <int> numVect2 = {};
cout << "Input 5 numbers into a vector: " << endl;
for (int i = 0; i < 5; i++) {
cin >> numVect2[i];
}
return numVect2;
}
// void VectorRow();
// void VectorStack();
// void VectorTwoStacks();
void OutputNumbers(vector <int> numVect) {
cout << "Vector: " << endl;
for (auto i : numVect) {
cout << i << " ";
}
cout << endl;
}
int main() {
vector <int> numVect = {4, 5, 6, 7, 8};
enum menu {Input = 1, Row = 2, Stack = 3,
Twostacks = 4, Numbers = 5};
int choice;
do {
cout << "1. Input numbers\n";
cout << "2. Row\n";
cout << "3. Stack\n";
cout << "4. Two stacks\n";
cout << "5. Output numbers\n";
cout << "6. End\n";
cout << "--------------------------\n";
cout << "Choice: "; cin >> choice; cout << endl;
switch (choice) {
case Input: InputNumbers(numVect); break;
// case Row: VectorRow(); break;
// case Stack: VectorStack(); break;
// case Twostacks: VectorTwoStacks(); break;
case Numbers: OutputNumbers(numVect); break;
}
} while (choice != 6);
return 0;
}
Also, when I run the function 'InputNumbers()', it stops the terminal after user inputs the [0] element for 'numVect2'
Input 5 numbers into a vector:
1
PS C:\Users\leval\Desktop\majasdarbi\praktiskais_darbs2> 2
2
PS C:\Users\leval\Desktop\majasdarbi\praktiskais_darbs2>