Question
Attempting to validate input, month < 1 || month > 13. First invalid brings invalid input message, valid input brings up invalid input message, second
Attempting to validate input, month < 1 || month > 13. First invalid brings invalid input message, valid input brings up invalid input message, second valid input works.
while (!done)
{
if (month == 0 && year == 0)
{
done = true;
year = timeinfo->tm_year + 1900;
days = numberOfDays(timeinfo->tm_mon + 1, year);
cout << " The current month " << months[timeinfo -> tm_mon] << " "
<< year << " has " << days << " days.";
cout << endl;
break;
}
else if (month < 1 || month > 12)
{
cout << " Invalid month entry, try again.";
cout << " Enter the month as (1-12), space, and year as (2017)." << endl;
cin >> month;
cin >> year;
}
else
{
days = numberOfDays(month, year);
cout << " " << days << " days" << endl;
}
if (!done)
{
cout << " Enter the month as (1-12), space, and year as (2017).";
cout << " To quit, enter 0 for month and 0 for year." << endl;
cout << endl;
cin >> month;
cin >> year;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started