Here's your code, with [
code][/code] tags and some indentation:
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
|
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
bool leap_year(int year)
{
bool leap;
if ((year % 4 == 0 && year % 100!=0) || (year % 400 == 0) || (year > 1582))
{
return true;
}
else
{
return false;
}
}
int main()
{
cout<<"Enter a Year: ";
int num;
cin>> num;
bool leap_year(int year);
{
return true;
cout << num << "is a leap year.";
return false;
cout << num << "is not a leap year.";
return 0;
}
}
|
Let's step through your program, starting at the beginning of
main():
1) Prints "Enter a year: "
2) Declares an
int
variable named
num
3) Asks for input for that variable
4) The statement
bool leap_year(int year);
doesn't do anything. You can't define functions inside of
main(), and even if you could, it would still be an error because of the semicolon.
5) The curly brace after that line is the start of a new block, but for all intents and purposes, that doesn't have any effect on your program.
6) The program returns
true
(1, probably) at this point.
Oh, and by the way, your
is_leap function isn't even correct:
if ((year % 4 == 0 && year % 100!=0) || (year % 400 == 0) || (year > 1582))
You're saying that any year past 1582 is a leap year.