I'm writing a program for my C++ class, this is a short clip of it:
for(customer = 1; customer <= 5; customer++)
{
customer_Num[customer][2] = rand() % 999 + 1; // Receipt number
cout << "Customer Name:" << endl;
getline(cin,customer_Non[customer][1]);
cout << "Customer's address:" << endl;
getline(cin,customer_Non[customer][2]);
cout << "Customer's age:" << endl;
cin >> customer_Num[customer][1];
cin.ignore(2);
//TEST PHASE
cout << customer_Num[customer][2] << endl
<< customer_Non[customer][1] << endl
<< customer_Non[customer][2] << endl
<< customer_Num[customer][1] << endl
<< quantity << endl;
}
Now if I don't put the cin.ignore, when it gets to customer #2, it'll skip Customer Name: and move on to Customer's address. I think its safe to assume that the reason I need cin.ignore is because of the \n when I press enter after customer's age, but then I would think that I would only need cin.ignore(); but without a number in there (which is default 1 I believe), I get the same result as before, skipping through the second Customer name.cin.ignore(2); seems to work just fine but I want to understand why. Can someone explain to me why I need that 2 in there?