Leap Year/ finding if a date is valid or not.

Basically what I'm trying to do for now is determine if the user inputted date is valid or not only based on the months and see if it is a leap year or not.
For now I have not worked on the days part but my program has you enter the day anyways.

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
#include <iostream>

using namespace std;

int main()
{
    int mm, dd, year;
    bool leapYear ( int year );

    cout << "Please enter your date (mm dd year)." << endl;
    cin >> mm >> dd >> year ;

    if ( mm < 1 || mm > 12)
    {
        cout << "N" << endl;

    if (leapYear ( year ))
    {
        cout << "It is a leap-year!" << endl;
    }
    else
    {
    cout << "sorry it's not" << endl;
    }
    return 0;
}

bool leapYear ( int year )
{
    if ((( year % 4 == 0) && (! ( year % 100 == 0))) || (( year % 4 == 0) && (! ( year % 100 == 0)) && ( year % 400 == 0)));
    {
        return true;
    }
     else
    {
        return false;
    }
}


BUT for some reason I keep getting the errors:

29: error: a function-definition is not allowed here before '{' token
and
38: error: expected `}' at end of input

And I don't know what is wrong with my code.
The first problem is you forgot the closing brace on line 16 to close off the if statement.

The second problem is there shouldn't be a ; at the end of the if statement on line 30.
OH so that's what it was. Thanks a lot but I'm now getting a different error:

35: error: expected `(' before '{' token
Nevermind got it, it was cause in line 34 I accidentally had it as "else if" when it was supposed to be "else"
Topic archived. No new replies allowed.