In the program below I need to get month to hold the first two digits of date, day two hold the digits 3 & 4, & year to hold the last four digits. Any idea on how I can accomplish that?
#include <iostream>
#include <string>
#include "functions.h"
int main()
{
std::cout << "Please enter a number. ";
int date = 0;
std::cin >> date;
int digits = getNrDigits( date );
if ( digits == 8 )
{
std::cout << "Number of digits is good" << std::endl;
int month = 1;
int day = 2;
int year = 3;
}
else
{
std::cout << "Invalid number of digits" << std::endl;
}
return 0;
}
// FUNCTIONS
int getNrDigits( int my_int )
{
int local_int = my_int;
int count = 0;
while ( local_int > 0 )
{
local_int /= 10;
count++;
}
return count;
}