Reputation: 1
New to programming so I'm struggling to get this code to output properly:
int main()
{
cout << "Please enter a sequence integers:" << '\n';
cout << "Enter the character | to quit." << '\n';
char quitting;
cin >> quitting;
if (quitting == '|')
{
cout << "Press any key to confirm exit.";
return 2;
}
vector<int> numbers;
for (int being_read; cin >> being_read;)
{
numbers.push_back(being_read);
cout << numbers[numbers.size()-1] << '\n';
}
}
The first element is never output properly. If the first value being read is a single digit number, it will ignore it and start counting from the second element (1,2,3,4 will output 2,3,4). If it's more than one digit it will output all elements, but the first element will truncate in a way I can't understand. 111, 222, 333 will output 11, 222, 333, 444 while 105, 106, 107 will output 5, 106, 107.
Upvotes: 0
Views: 58
Reputation: 383
The first digit lies in quitting. If you remove it the code runs fine
Upvotes: 1