i need help writing this code? thats what i have. it has some to do with it.write a program that prompts the user to enter the date in mm/dd/yyyy format the program should use a single input statement to accept the date, storing each piece of the date into a appropriate variable demonstrate that the input was obtained directly by outputting the month, day, and the year to the screen
#include <iostream>
int main()
{
int CurrentDate, Month, Day, Year;
std::cout << "Please enter a date in mmddyyyy format (Example: 06092014): ";
std::cin >> CurrentDate;
if ( CurrentDate < 0 || Month < 0 || Day < 0 || Year < 0 )
{
std::cout << "Please enter positive numbers" << std::endl;
return 0;
}
std::cout << "The original mmddyyyy date of " << CurrentDate << " has been converted to mmddyyyy format below" << std::endl;
std::cout << Month << " / " << Day << " / " << Year << std::endl;
When you read in the CurrentDate, you need to parse the individual parts. There are multiple ways to do this. One way is to convert the integer into a string and create sub-strings. Once you have the individual substrings, you could print them back out with "/"s in between. It may not be the best way, but it is simple enough to follow.