What I want to do with cin.ignore(256,'\n');
is to clean the keyboard buffer, so that in the 2nd loop while
can enter the data.
But the monento execute it I realize I have not achieved my goal, and because of my inexperience I do not know what error I've been committing.
Here is the code of what I have achieved:
#include<iostream>
using namespace std;
int main() {
int a = 0, b = 0, n,i;
while (cin >> n) {// ingreso " 1 2 3 " y un caracter para cerrar el bucle
a += n;
}
cin.ignore(256,'\n');
while (cin >> i) {// ingreso " 4 5 6 " y un caracter para cerrar el bucle
b += n;
}
cout << a <<' '<< b << endl;
}
If everything had gone as planned, the output would be: 6 15
BUT the output I get is: 6 0
.