C++计算出该日是本年中的第几天?

C++计算出该日是本年中的第几天

任务描述

定义一个结构体变量(包括年、月、日),编写程序,要求输入年、月、日,程序能计算并输出该日在本年中是第几天。注意闰年问题。

测试输入:`

2000 12 20

预期输出:

12/20 is the 355th day in 2000

测试输入:

1998 10 1

预期输出:

10/1 is the 274th day in 1998

源代码:

#include <iostream>
using namespace std;
struct
{ 
int year;
int month;
int day;
}date;

int main()
{
int days;
cin>>date.year>>date.month>>date.day;

// 请在此添加代码
    /********** Begin *********/
        days=0;
    int i;
        int year1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int year2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    if((date.year%4==0&&date.year%100!=0)||(date.year%400==0)){
                for(i=0;i<date.month-1;i++){
                        days+=year2[i];
                }
        }else{
                for(i=0;i<date.month-1;i++){
                        days+=year1[i];
                }
        }
    days+=date.day;
    /********** End **********/

cout<<date.month<<"/"<<date.day<<" is the "<<days<<"th day in "<<date.year<<"."<<endl;
return 0;
}