When taking input from the user as a date, I would like be able to extract the numbers whether the format is mm/dd/yy or m/d/yy. I can only figure out how to do one or the other, but not both. How might I go about this? I am new to C++ coming from python. Here is my code.
#include <iostream>
#include <string>
using namespace std;
bool isMagicDate(string year, string month, string day)
{
int int_month = stoi(month);
int int_day = stoi(day);
int int_year = stoi(year);
if (int_month * int_day == int_year)
return true;
else return false;
}
int main()
{
string date;
cout << "enter a date in the format mm/dd/yy: " << endl;
cin >> date;
string month = date.substr(0,2);
string day = date.substr(3,2);
string year = date.substr(6,2);
cout << "the month is " << month << endl
<< "the day is " << day << endl
<< "the year is " << year << endl;
cout << "the date you entered is " << date << endl;
bool magic = isMagicDate(year, month, day);
cout << "Is the date magic? " << magic << endl;
return 0;
}