So I am pretty new to coding and am having some issues with storing user input into a vector using the push_back function. can some one tell me what I am doing wrong?
vector<int> user_nums;
switch(selection){
case 'P':
case 'p':
if(user_nums.empty()){
cout << "[]- list is empty" << endl;
}else{
for(auto nums: user_nums)
cout <<"[ " << nums << " ]" << endl;
}
break;
case 'A':
case 'a':
int new_num;
cout << "\nEnter a number you would like to add: ";
cin >> new_num;
user_nums.push_back(new_num);
cout << new_num << " was added" << endl;
break;
This is in a do while loop. The code executes just fine, the problem is when I prompt the user to add a new number the value does not store in the vector. So when the user makes the selection to print the numbers, the list still shows empty.