Hello everyone,
My program is to count total days between two entered by user dates, during the compilation I am getting these errors and do not understand why, and what they mean.
Here is the errors:
Code:
: error C2143: syntax error : missing ';' before 'type'
: error C2065: 'B' : undeclared identifier
: error C2224: left of '.day' must have struct/union type
: error C2065: 'B' : undeclared identifier
: warning C4013: 'print_date' undefined; assuming extern returning int
and here is a program;
Code:
#include<stdio.h>
int DaysPerMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct Sdate //declare structure
{
int month;
int day;
int year;
} begin, end;
int isLeapYear(int a)// determine if it is a leap year
{
if((a%4==0&&a%100!=0)||a%400==0)
{
return 1; //it,s a leap year
}
else
//not a leap year
return 0;
}
struct Sdate EnterDate(void) //function to enter dates
{
int d,m,y;
struct Sdate A;
do
{
printf("Enter the month: ");
scanf("%i", &m);
if(m<1||m>12)
printf("Invalid entry, try again!\n");
}while(m<1||m>12);
do
{
printf("Enter the day: ");
scanf("%i", &d);
if(d<1||d>DaysPerMonth[m])
printf("Invalid Entry,try again!\n");
}while(d<1||d>DaysPerMonth[m]);
do
{
printf("Enter the year (yyyy)");
scanf("%i", &y);
if(y<0)
printf("Invalid entry, try again!\n");
}while(y<0);
printf("\n");
A.month=m;
A.day=d;
A.year=y;
return(A);
}//end of the function
void swap_dates(void) // function to swap dates
{
struct Sdate temp;
temp=begin;
begin=end;
end=temp;
}
void validate(void) // validating dates
{
if(begin.year>end.year)
{
swap_dates();
}
if((begin.year==end.year)&&(begin.month>end.month))
{
swap_dates();
}
if(begin.year==end.year&&begin.month==end.month&&begin.day>end.day)
{
swap_dates();
}
}
int count_days(void)
{
int i;
int days=0;
int days_per_year=365;
for(i=(begin.year+1); i<end.year; ++i)//how many days beetween full years
{
days=days+(days_per_year+isLeapYear(i));
}
for(i=begin.month; i<=13; ++i)//how many days in a beginning year+ already counted days
{
if(begin.year%4==0&&begin.year!=100&&begin.month==2)
{
days+=(DaysPerMonth[i]+1);
}
else
days+=DaysPerMonth[i];
}
for(i=1; i<=end.month; ++i)//how many days in a ending year+ already counted days
{
if(end.year%4==0&&end.year!=100&&end.month==2)
{
days+=(DaysPerMonth[i]+1);
}
else
days+=DaysPerMonth[i];
return days; //returning total days
}
void print_date(struct Sdate B)
{
printf("%i/", B.month);
printf("%i/", B.day);
printf("%i\n", B.year);
}
int main(void)
{
begin=EnterDate();
end=EnterDate();
validate();
print_date(begin);
print_date(end);
printf("Total days between these two dates is %i\n", count_days());
}
Can anyone explain what is wrong.
Thank you.