You have an unconditional return 0;
after the if
statements. All but the first if
should be an else if
and the code for the correct date should be in an else
block. Alternatively, return at the end of every error case, proceeding only if each check passes—although this will lead to a lot of duplication.
Enclosing all those statements in a single set of braces merely creates a lexical scope for variable declarations, probably not what you meant.
The code to check validity could instead be a do
… while
loop that retries while you enter invalid dates, and you should calculate the day of the week after you fall through that loop, which will happen when the date is valid.
solved Gregorian Calendar in C