View Code of Problem 81

#include<stdio.h>
struct date{
	int month;
	int day;
	int year;
};
bool leapyear(struct date d);
int sum(struct date d);
int main()
{
	struct date myday;
	int day;
	scanf("%i %i %i",&myday.year,&myday.month,&myday.day);
	day=sum(myday);
	printf("%d\n",day);
	return 0;
}
bool leapyear(struct date d)
{
	if(d.year%4==0&&d.year%100!=0||d.year%400==0)
	{
		return true;
	}
	else return false;
}
int sum(struct date d)
{
	int n=0;
	int daysperMounth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	if(leapyear(d))
	{
		daysperMounth[1]=29;
	}
	for(int i=0;i<d.month-1;i++)
	{
		n+=daysperMounth[i];
	}
	n+=d.day;
	return n;
}
/*
Main.c:7:1: error: unknown type name 'bool'
 bool leapyear(struct date d);
 ^
Main.c:18:1: error: unknown type name 'bool'
 bool leapyear(struct date d)
 ^
Main.c: In function 'leapyear':
Main.c:20:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  if(d.year%4==0&&d.year%100!=0||d.year%400==0)
                ^
Main.c:22:10: error: 'true' undeclared (first use in this function)
   return true;
          ^
Main.c:22:10: note: each undeclared identifier is reported only once for each function it appears in
Main.c:24:14: error: 'false' undeclared (first use in this function)
  else return false;
              ^
Main.c:25:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
*/

Double click to view unformatted code.


Back to problem 81