Hello..
Supposing that i have this code..i want it to end after a character is pressed..but i dont know what to add...i can end it if input is negative or zero..but not char..i tried some experiments but it will end up debug assertion fail..help would be great..
// adds numbers depending on user
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<int> v;
vector<int>::iterator it;
int num,n,sum=0;
cout<<"Enter series of numbers: ";cin>>num;
while (num > 0)
{//here
v.push_back(num);
cin>>num;
}
cout<<"How many numbers to add: ";cin>>n;
for(it = v.begin(); it < v.begin()+n ;it++)
{
sum+=*it;
}
cout<<"Sum of ";copy(v.begin(),v.begin()+ n ,ostream_iterator<int>(cout, ", "));
cout<< "is "<<sum;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cin.get();
return 0;
}