c++中给定某个日期,计算出这一日期是该年的第几天,我不知道哪里出错了?
#include<iostream>#include<iomanip>usingnamespacestd;structdate{inty;intm;intd;};void...
#include<iostream>
#include<iomanip>
using namespace std;
struct date
{
int y;
int m;
int d;
};
void main()
{
int a[12]={31,28,31,30,31,30,31,30,31,30,31,30};
int b[12]={31,29,31,30,31,30,31,30,31,30,31,30};
int sum=0,i=0;
date t;
cin>>t.y;
cin>>t.m;
cin>>t.d;
if((t.y%400==0)&&((t.y%100!=0)&&(t.y%4==0)))
{
if(t.m=1)
cout<<t.d;
else
{
for(;t.m-1>0;t.m--)
{
sum+=b[i];
i++;
}
cout<<sum+t.d;
}
}
else
{
if(t.m =1)
cout<<t.d;
else
{
for(;t.m-1>0;t.m--)
{
sum+=b[i];
i++;
}
cout<<sum+t.d;
}
}
} 展开
#include<iomanip>
using namespace std;
struct date
{
int y;
int m;
int d;
};
void main()
{
int a[12]={31,28,31,30,31,30,31,30,31,30,31,30};
int b[12]={31,29,31,30,31,30,31,30,31,30,31,30};
int sum=0,i=0;
date t;
cin>>t.y;
cin>>t.m;
cin>>t.d;
if((t.y%400==0)&&((t.y%100!=0)&&(t.y%4==0)))
{
if(t.m=1)
cout<<t.d;
else
{
for(;t.m-1>0;t.m--)
{
sum+=b[i];
i++;
}
cout<<sum+t.d;
}
}
else
{
if(t.m =1)
cout<<t.d;
else
{
for(;t.m-1>0;t.m--)
{
sum+=b[i];
i++;
}
cout<<sum+t.d;
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询