Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. string userEntry, strDay, strMon, strYr;
  8. int firstDashLoc, secondDashLoc, lengthStr, month, day, year;
  9. bool magicResult;
  10.  
  11.  
  12. bool isMagicDate(int month, int day, int year);
  13.  
  14. int main()
  15. {
  16. cout << "Enter date in the format mm/dd/yy ";
  17. cin >> userEntry;
  18. lengthStr = userEntry.length();
  19. firstDashLoc = userEntry.find('/', 0);
  20. strMon = userEntry.substr(0, firstDashLoc);
  21. month = stoi(strMon);
  22. cout <<"month is " << month << endl;
  23.  
  24. secondDashLoc = userEntry.find('/', firstDashLoc +1);
  25. strDay = userEntry.substr(firstDashLoc + 1, secondDashLoc);
  26. day = stoi(strDay);
  27. cout <<"day is " << day << endl;
  28.  
  29. strYr = userEntry.substr(secondDashLoc + 1, lengthStr);
  30. year = stoi(strYr);
  31. cout <<"year is " << year << endl;
  32. magicResult = isMagicDate(month, day, year);
  33. if magicResult == true
  34. cout << "It's magic!" << endl;
  35. else
  36. cout << "nah" << end1;
  37. return 0;
  38. }
  39.  
  40. bool isMagicDate(int month, int day, int year)
  41. {
  42. if (month * day == year)
  43. return true;
  44. else
  45. return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement