I have an assignment due and I'm in my first semester of programming so its pretty basic stuff.
Our assignment is to write a function that accepts a date as a string parameter assumed to be in the form mm/dd/yyyy and outputs in the form
Day: dd
Month: mm
Year: yyyy
Here's my code so far without all the neatness/comments:
CODE
#include <iostream>
#include <string>
using namespace std;
void date(string a)
{
int i = a.size();
cout << "Size of String = " << i << endl;
string day = a.substr(3, 4);
cout << "Day: " << day << endl;
string month = a.substr(0, 2);
cout << "Month: " << month << endl;
string year = a.substr(6, 10);
cout << "Year: " << year << endl;
}
int main()
{
string x;
cout << "Enter a date (mm/dd/yyyy): ";
cin >> x;
date(x);
}
And here's the output I'm getting:
Enter a date (mm/dd/yyyy): 10/02/1985
Size of String = 10
Day: 02/1
Month: 10
Year: 1985
I can't seem to get the 3rd and 4th position just by themselves no matter what I do. Any help?