fork(1) download
  1. #include <iostream>
  2. #include <limits>
  3. using namespace std;
  4.  
  5. bool validateDateSize(int day1, int month1, int year1) {
  6. return true;
  7. }
  8. bool validateDateIntegrity(int day1, int month1, int year1) {
  9. return day1>0 && month1>0 && year1>0;
  10. }
  11. int main() {
  12. int day1, month1, year1;
  13. char buffer;
  14. do // This do while loop forces the user to enter a valid date before moving on
  15. {
  16. cout << "Enter the lent date in the format dd/mm/yyyy: " << endl;
  17. cin >> day1 >> buffer >> month1 >> buffer >> year1;
  18. if(cin.fail())
  19. {
  20. cin.clear(); //reset error flags
  21. cin.ignore(numeric_limits<streamsize>::max(),'\n'); // and ignore characters until the next newline
  22. continue;
  23. }
  24. }
  25.  
  26. while (!validateDateSize(day1, month1, year1) || !validateDateIntegrity(day1, month1, year1)); // your code goes here
  27. cout<<"Ok:"<<day1<<" - "<<month1<<" - "<<year1<<endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 15232KB
stdin
12/A/2017
21/3/2018

stdout
Enter the lent date in the format dd/mm/yyyy: 
Enter the lent date in the format dd/mm/yyyy: 
Ok:21 - 3 - 2018