When I compiled this and added a few printf lines to help with the debugging before I asked for help, the leapyr function seemed to be working as planned. The problem was located somewhere else.
no actually the problem is there. and it's related to what i was talking about, 'local scope'
you have the variable 'leap' declared (but not defined) globally. there's no telling what this value may be
THEN you declare the variable 'leap' as an integer, local to the function "leapyr". this function calculates whether or not the year is a leap year (incorrectly, i might add... more on that later).
your print statement within "leapyr" prints out the value it calculates, and then attempts to return that value to the calling function (main)
however, "main" is not accepting the return value, as i mentioned previously, because you have no assignment. you probably think that the value "leap", defined globally, is modifed to whatever the "leapyr()" function changed it to.
But this is not the case.
because "leap" in the function "leapyr" is declared locally, it is modified local to the function's local runtime stack, only. the global variable "leap" is untouched. Like my analogy of the two "Joe Smiths" living 3000 miles away. here is the danger of using the same variable names, you confuse the programmer.
the quickest fix is to completely remove the "int leap;" declaration in your "leapyr" function, then it will use the global variable.
that said, globally-scoped variables, except in certain circumstances when properly used, are generally a very poor way to program. you see you have so much trouble with this trivial program, imagine 50,000 lines of code littered with globals!
you have other problems that may not be noticed on your compiler: you dont initialize variables such as "totaldays". some compilers automatically initialize to zero. many do not. this code will be broken in many environments.
you need to declare your functions prototypes before being called. your compiler doesnt care, but many (most!) will. functions that are typed with a return value, must return that type value. "int inputdata" must return an int, or better yet, be declared as "void inputdata"
finally your leap year calculation is wrong. the case "year % 4 == 0" will always return a leap = TRUE, and the other conditionals will therefore always be ignored. it should be
leap = 0; //always define vars first!
if (year % 4 == 0)
leap = 1;
if (year % 100 == 0)
leap = 0;
if (year % 400 == 0)
leap = 1;
or, preferably:
if (year % 400 == 0)
leap = 1;
else if (year % 100 == 0)
leap = 0;
else if (year % 4 == 0)
leap = 1;
else
leap = 0; // or force default defines!!
.