Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- using namespace std;
- string userEntry, strDay, strMon, strYr;
- int firstDashLoc, secondDashLoc, lengthStr, month, day, year;
- bool magicResult;
- bool isMagicDate(int month, int day, int year);
- int main()
- {
- cout << "Enter date in the format mm/dd/yy ";
- cin >> userEntry;
- lengthStr = userEntry.length();
- firstDashLoc = userEntry.find('/', 0);
- strMon = userEntry.substr(0, firstDashLoc);
- month = stoi(strMon);
- cout <<"month is " << month << endl;
- secondDashLoc = userEntry.find('/', firstDashLoc +1);
- strDay = userEntry.substr(firstDashLoc + 1, secondDashLoc);
- day = stoi(strDay);
- cout <<"day is " << day << endl;
- strYr = userEntry.substr(secondDashLoc + 1, lengthStr);
- year = stoi(strYr);
- cout <<"year is " << year << endl;
- magicResult = isMagicDate(month, day, year);
- if magicResult == true
- cout << "It's magic!" << endl;
- else
- cout << "nah" << end1;
- return 0;
- }
- bool isMagicDate(int month, int day, int year)
- {
- if (month * day == year)
- return true;
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement