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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!