1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Create function for reading and validating time.
void Time (struct store_time& begin_end, struct store_date& start_end)
{
// Prompt user to enter a valid time between 00:00:00 and 23:59:59.
cout << "Please enter the start hour, minute, second between 00:00:00 and 23:59:59." << endl;
cin >> start_time.hour >> start_time.minute >> start_time.second;
if ( start_time.second >= 60 )
{
cout << "Invalid input for seconds." << endl;
return;
}
else if ( start_time.minute >= 60 )
{
cout << "Invalid input for minutes." << endl;
return;
}
else if ( start_time.hour >= 24 )
{
cout << "Invalid input for hour." << endl;
return;
}
else
cout << endl;
cout << "Please enter the end hour, minute, second between 00:00:00 and 23:59:59." << endl;
cin >> end_time.hour >> end_time.minute >> end_time.second;
if ( end_time.second >= 60 )
{
cout << "Invalid input for seconds." << endl;
return;
}
else if ( end_time.minute >= 60 )
{
cout << "Invalid input for minutes." << endl;
return;
}
else if ( end_time.hour >= 24 )
{
cout << "Invalid input for hour." << endl;
return;
}
else
cout << endl;
// Validate the user time is within parameters.
cout << "The start time is: " << setfill('0') << setw(2) << start_time.hour << ':';
cout << setfill('0') << setw(2) << start_time.minute << ':';
cout << setfill('0') << setw(2) << start_time.second << endl;;
cout << "The end time is: " << setfill('0') << setw(2) << end_time.hour << ':';
cout << setfill('0') << setw(2) << end_time.minute << ':';
cout << setfill('0') << setw(2) << end_time.second << endl;
cout << endl;
}
// Create function for reading and validating a date.
void Date (struct store_date& start_end)
{
// Prompt user to enter a valid start and end date between 1/1/100 and 12/31/2000.
cout << "Please enter the start year, month, and day between 100/1/1 and 2000/12/31" << endl;
cin >> start_date.year >> start_date.month >> start_date.day;
cout << endl;
cout << "Please enter the end year, month, and day between 100/1/1 and 2000/12/31" << endl;
cin >> end_date.year >> end_date.month >> end_date.day;
cout << endl;
// Validate the date to be within set parameters.
// When start/end year is under 100, over 2000, or start year is greater then end year, it is invlaid.
if ( start_date.year < 100 || start_date.year > 2000 || start_date.year > end_date.year )
cout << "Invalid start year. Please try again." << endl;
else if( end_date.year < 100 || end_date.year > 2000 )
cout << "Invalid end year. Please try again" << endl;
// Otherwise, validate month, and display given dates.
else
{
// When month number is less than 1 or greater than 12, input is invalid.
if ( start_date.month < 1 || start_date.month > 12 )
cout << "Invalid starting month. Please try again" << endl;
else if ( end_date.month < 1 || end_date.month > 12 )
cout << "Invalid ending month. Please try again." << endl;
// Otherwise, display dates.
else
{
cout << "The start date is: " << start_date.day << ' ' << month_name[start_date.month-1] << ", " << start_date.year << endl;
cout << "The end date is: " << end_date.day << ' ' << month_name[end_date.month-1] << ", " << end_date.year << endl;
cout << endl;
}
}
}
|