help writting this code

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;

Month = ( CurrentDate / 100 ) % 100;
Day = CurrentDate % 100;
Year = ( CurrentDate / 10000 );

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;

return 0;
}
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.

Hope this helps!
Please use

1
2
  string code_brackets; 
  code_brackets = "[code][ /code]";
Last edited on
Topic archived. No new replies allowed.