Как после добавления чисел в вектор вывести сумму первых (заданных пользователем) чисел
Здравстуйте, как после функции while не прервать программу, а продолжить вводить данные. (отесть ввести y)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
cout << "enter some numbers \n";
vector<int> v;
int x;
while (cin >> x)
v.push_back(x);
cout << "the sum of which first numbers would you like to display \n";
int y;
cin >> y;
int res = 0;
for (int i = 0; i < y; ++i)
res += v[i];
cout << "result " << res << '\n';
return 0;
}