Why I have to cin.ignore() ?
Hello there
Code:
#include <iostream>
using namespace std;
int multiply(int x, int y);
int main()
{
int x,y;
cout << "Insert the value of x: ";
cin >> x;
//cin.ignore();
cout << "Insert value y: ";
cin >> y;
//cin.ignore();
cout << "X multiple Y equals in " << multiply(x,y) << endl;
return 0;
}
int multiply(int x, int y) {
return (x*y);
}
Comment or not, cin.ignore(); does nothing in this program output. I read somewhere that we use this function to throw <Enter> away, but I don't understand what does it means... I suppose Enter represents a Carriage Return CR character or something like that, but again... I can't figure out the meaning of use the cin.ignore() since the program output is identical the same using it or not. :confused: