Some of the length values in the cin.getline() don't seem correct.
Because I can't see all of the code, it's a bit hard to tell. But for example:
30 31 32
|
cout<<"\nEnter Date Borrowed (dd/mm/yyyy): ";
cin.getline(dateBorrowed2, 10);
cin.ignore(1, '\n');
|
The date is requested in the format "dd/mm/yyyy", That's 10 characters. Allowing one byte for the null terminator, that means we'd expect this definition:
and the getline() should also specify 11, otherwise the last character of the date will be lost. Perhaps the safest way to code that is to put
|
cin.getline(dateBorrowed2, sizeof(dateBorrowed2) );
|
and let the compiler work out the correct length for us.
Now there are a couple of other things to consider. What happens if the user accidentally types one (or more) character too many? Well, the getline will read the required 10 characters, but since it didn't encounter the newline character, it sets the
fail
flag for cin. In that case we need to clear the flag, and also discard characters from the input buffer until the newline is found. (If the user entered a date of the correct length or shorter, we don't need to do this, as getline will have already discarded the newline character for us.
So, with some basic error-checking, the code will look like this:
30 31 32 33 34 35
|
cout << "\nEnter Date Borrowed (dd/mm/yyyy): ";
if (!cin.getline(dateBorrowed2, sizeof(dateBorrowed2)))
{
cin.clear();
cin.ignore(1000, '\n');
}
|
The same principle applies to all of the getline() statements here.
See the reference page on getline:
http://www.cplusplus.com/reference/istream/istream/getline/