Leap year function errors

Hello,

I'm receiving multiple errors after creating a fn. to return if a year is a leap year or not.

Getting errors such as:
'isLeapYear' function does not take 0 arguments
redefinition of formal parameter 'year'

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
39
40
41
42
43
44
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

bool isLeapYear(int year);


int main() {

	isLeapYear(int year);

	system("pause");
}

bool isLeapYear(int year) {
	
	int year = int();
	int leapYear = int();
	
	cin >> year;

	if (year % 4 == 0) {
		if (year % 100 == 0) {
			if (year % 400 == 0) {
				cout << "This year is a leap year." << endl;
			}
			else {
				cout << "This year is not a leap year." << endl;
			}
		}
		else {
			cout << "This year is not a leap year." << endl;
		}
	}
	else {
		cout << "This year is not a leap year." << endl;
	}

	return leapYear;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

bool isLeapYear(int year);

int main() {
    int year = 0;
    cout << "Enter a year: ";
    cin >> year;
    if (isLeapYear(year))
        cout << "This year is a leap year.\n";
    else
        cout << "This year is not a leap year.\n";
    return 0;
}

bool isLeapYear(int year) {
    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

closed account (E0p9LyTq)
You can't create a variable as a function parameter.

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
39
40
41
42
43
44
45
46
#include <iostream>

bool isLeapYear(int);

int main()
{
   int year;

   std::cout << "Enter the year: ";
   std::cin >> year;

   bool leapYear = isLeapYear(year);
}

bool isLeapYear(int year)
{

   if (year % 4 == 0)
   {
      if (year % 100 == 0)
      {
         if (year % 400 == 0)
         {
            std::cout << "This year is a leap year.\n";
            return true;
         }
         else
         {
            std::cout << "This year is not a leap year.\n";
            return false;
         }
      }
      else
      {
         std::cout << "This year is not a leap year.\n";
         return false;
      }
   }
   else
   {
      std::cout << "This year is not a leap year.\n";
      return false;
   }

   return false;
}
Mine actually gives the correct answer, if you're interested in that kind of thing.
closed account (E0p9LyTq)
@tpb, your version is one that is advanced compared to what the OP posted.
@FurryGuy, That's true. Yours shows him how to get his original idea working. :-)
Topic archived. No new replies allowed.