View Code of Problem 81

#include <stdio.h>
struct date
{
	int year;
	int month;
	int date;
};
int main()
{
	date time;
	int sum = 0,i;	 
	scanf("%d%d%d",&time.year,&time.month,&time.date);
	int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	for(i=0;i<time.month-1;i++)
	{
		sum+=a[i];
	}
	sum = sum + time.date;
	if(((time.year%4==0&&time.year%100!=0) || (time.year%400==0)) && time.month>2)
	{
		sum+=1;
	} 
	printf("%d",sum);
	return 0;
}
/*
Main.c: In function 'main':
Main.c:10:2: error: unknown type name 'date'
  date time;
  ^
Main.c:12:22: error: request for member 'year' in something not a structure or union
  scanf("%d%d%d",&time.year,&time.month,&time.date);
                      ^
Main.c:12:33: error: request for member 'month' in something not a structure or union
  scanf("%d%d%d",&time.year,&time.month,&time.date);
                                 ^
Main.c:12:45: error: request for member 'date' in something not a structure or union
  scanf("%d%d%d",&time.year,&time.month,&time.date);
                                             ^
Main.c:14:16: error: request for member 'month' in something not a structure or union
  for(i=0;i<time.month-1;i++)
                ^
Main.c:18:18: error: request for member 'date' in something not a structure or union
  sum = sum + time.date;
                  ^
Main.c:19:11: error: request for member 'year' in something not a structure or union
  if(((time.year%4==0&&time.year%100!=0) || (time.year%400==0)) && time.month>2)
           ^
Main.c:19:27: error: request for member 'year' in something not a structure or union
  if(((time.year%4==0&&time.year%100!=0) || (time.year%400==0)) && time.month>2)
                           ^
Main.c:19:49: error: request for member 'year' in something not a structure or union
  if(((time.year%4==0&&time.year%100!=0) || (time.year%400==0)) && time.month>2)
                                                 ^
Main.c:19:71: error: request for member 'month' in something not a structure or union
  if(((time.year%4==0&&time.year%100!=0) || (time.year%400==0)) && time.month>2)
                                                                       ^
Main.c:10:7: warning: variable 'time' set but not used [-Wunused-but-set-variable]
  date time;
       ^
*/

Double click to view unformatted code.


Back to problem 81