注册 登录
编程论坛 C++教室

输入今天是x年x月x日,和天数,输出这么多天后是几年级月几日;例如2016 3 9 24000,输出2081 10 5

鱼王舌 发布于 2016-03-12 14:06, 2303 次点击
各位大神,小弟是个C语言新手,求指教:
#include <iostream.h>
void main()
{
    int a,b,c,n,H,I,m,sum=0,i;
    cout<<"please input year month and year and 要增加的天数:";
    cin>>a;cin>>b;cin>>c;cin>>n;
    H=n%(365*4+1);
    I=H/365;
    a=a+I+n/(365*4+1)*4;
    m=H-(H/365)*365;
    if(b=1)m=m+c;
    else if(b=2)m=m+31+c;
    else if(b=3)m=m+31+28+c;
    else if(b=4)m=m+31+28+31+c;
    else if(b=5)m=m+31+28+31+30+c;
    else if(b=6)m=m+31+28+31+30+31+c;
    else if(b=7)m=m+31+28+31+30+31+30+c;
    else if(b=8)m=m+31+28+31+30+31+30+31+c;
    else if(b=9)m=m+31+28+31+30+31+30+31+31+c;
    else if(b=10)m=m+31+28+31+30+31+30+31+31+30+c;
    else if(b=11)m=m+31+28+31+30+31+30+31+31+30+31+c;
    else if(b=12)m=m+31+28+31+30+31+30+31+31+30+31+30+c;
    if(m>365)m=m-365;
    else
    {
      for(i=1;i<=12;i++)
      {
        if(i<=7&&i%2==1||i>7&&i%2==0)
            sum=sum+31;
        else if(i==2)sum=sum+28;
        else sum=sum+30;
        if(sum>=m)
            b=b+i;break;
      }
    }
    c=sum-m;
    cout<<"year"<<" "<<"mouth"<<" "<<"day"<<" "<<a<<" "<<b<<" "<<c<<endl;
}
输出只有年是对的,大神求助
0 回复
1