I'm having a bit of trouble with this one, the goal of this program is to enter in 1 to 5 numbers, with a maximum of 5, into a vector and then popping as many numbers as the user wants until the vector contains nothing. My problem is that I can't figure out how to print out the numbers contained in the vector. I also am thinking about putting something in to detect whether or not there is anything in the vector so that the user doesn't crash the program. Any ideas on how I can solve these two problems?
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int addnums;
int index;
char selection;
int counter = 0;
vector<int> values;
values.push_back(1);
values.push_back(2);
values.push_back(3);
values.push_back(4);
values.push_back(5);
do
{
cout << "How many entries would you like to add (up to 5): ";
cin >> addnums;
if (addnums <= 5)
{
for (index = 0; index < addnums; index++)
{
int tempnums;
cout << "Enter integer " << (index + 1) << ": ";
cin >> tempnums;
values.push_back(tempnums);
counter++;
}
}
if (addnums >= 6)
{
cout << "Please choose a number in the range of 1 and 5\n\n";
}
else
break;
}while (counter != addnums);
do
{
cout << "Press E to End or Press P to pop a value: ";
cin >> selection;
if(selection == 'p' || selection == 'P')
{
cout << "The integer you popped was: " ; << values.begin();
values.erase (values.begin());
}
else
break;
}while(selection == 'p' || selection == 'P');
return 0;
}