Flowchart or Pseudocode please. Design a program that will allow the user to inp
ID: 3766917 • Letter: F
Question
Flowchart or Pseudocode please.
Design a program that will allow the user to input a date value to three variables for month, day and a 4 digit calendar year. Validate the data so that month is 1-12 and so that the day is not less than 1 and not greater than the number of days for the corresponding month. Call a function that returns a value of true if the year is a leap year and false otherwise if the month is February in order to validate the day. Display a message to the user that confirms the validity of the date or the error that occured. A leap year is one that can be evenly divided by 4 unless it is also divisible by 100 OR it is evenly divisible by 400.
This is should to be written in pseudocode or a flowchart
Explanation / Answer
Pseudocode:
bool is_valid_date(day , month, year)
{
leap = is_leap(year);
if(month <1 || month >12 || day < 1 || year < 0)
return false;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if(day <=31)
return true
else
return false
}
else if (month == 4 || month == 6 || month == 9 || month == 11 )
{
if(day <= 30)
return true
else
return false
}
else // month == 2
{
if (leap == 1)
{
if(day <= 29)
return true;
else
return false;
}
else
{
if(day <= 28)
return true;
else
return false;
}
}
}
int is_leap( year)
{
if(year % 4 != 0)
return false;
else if(year %100 == 0 & year%400 != 0)
return false
return true; // other than above two cases;
}
for flow chart convert each if statement to a decition box and each return to output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.