Zebra0.com

cpp errorsInput a date as mm/dd/year

Input a date as mm/dd/year

In this example we ask the user to enter the date as mm/dd/year.

We need to check for lots of errors. The slash could be missing, the conversion from string to int could fail, and then it could still be an invalid date.

Since there will be three integers to convert, it is easier to write a function and write the try/catch block just once. Since we know that month, day, and year must all be positive, we return -1 as a signal that the conversion failed.