This is just an at home assignment so i can expand my knowledge of C++. what i am trying to do is write a series of numbers in console then print out how many positive and negative number there are.
for example
Input = 2 7 6 -2 -5 23 -2
Output = Total positive numbers = 4 Total negative numbers = 3
The problem is i do not know how to loop cin. while cin has a number in its buffer then continue else break out of loop.
i understand that while(cin >> buffer) does not work and causes a endless loop but i dont know of any function to check the buffer for cin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main(){
int pos, neg, zero, buffer;
cout << "Input series of number:";
while(cin >> buffer){
if(buffer > 0)
pos++;
elseif (buffer == 0)
zero++;
else
neg++;
}
cout << "Total positive numbers = " << pos << ": Total negative numbers = " << neg << ": Total zeros = " << zero;
}