Open conordb opened 7 years ago
My suggestions:
return EXIT_SUCCESS;
just for clarity and style guide (and because Richard says so haha)int isLeapYear (int year);
and put it between your #define
s and the line int main (int argc, char* argv[]) {
if (year%4 == 0){
and printf("%d\n",FALSE);
needs to go in a separate function. So basically:`int main (int argc, char *argv[]) { // some code here, including return EXIT_SUCCESS; }
int isLeapYear (int year) { //your leap year algorithm here }`
int year
is a leap year or not, you need to return a value. That means you're going to need another variable inside int isLeapYear
, for example you could make int leapYear
and then, instead of printing true or false in your function, you do something like this:if (year % 4 == 0) {
if (year % 100 == 0) {
if(year % 400 == 0) {
leapYear = TRUE;
} else {
leapYear = FALSE;
}
} else {
leapYear = TRUE;
}
} else {
leapYear = FALSE;
}
and then at the end of your function, you return leapYear;
and so, when the main function finishes running isLeapYear, it has a value for true or false that you can use. How to do this inside your int main:
int isItALeapYear; //or whatever you choose to call it
isItALeapYear = isLeapYear (year); //here we put whatever value isLeapYear has returned using the variable year and copying it into isItALeapYear. This is called **calling** the function.
Now the easy part. In your main function after that, you make some if statements which will make your program print "[year] is a leap year" if isItALeapYear is TRUE. (if false I'm sure you can figure out what to print)
Try and compile then submit to OL once it works. If you have any more questions ask me and if I don't have time I'll go over it with you on Wednesday.
Good luck!
// Program to test if year is a leap year // By Conor Briggs // Created 12 / 03 / 2017
include
include
include
define CAL_START 1582
define TRUE 1
define FALSE 0
int main (int argc, char* argv[]) {
int year;
int isLeapYear (int year);
}