回 帖 发 新 帖 刷新版面

主题:[讨论]1个c++问题

#include <iostream.h>
int isleap(int year);
int week1(int year,int month,int day,int i);
void outputweek(int week);
int year,month,day,i;
void main()
{
    
    cout<<"请输入年月日:";
    cin>>year>>month>>day;
     i=isleap(year);   
        static week=week1(year,month,day,i);
    
    outputweek(week);
}                                                    //主函数
int isleap(int year)
{
    if((year%4==0&&year%100!=0)||year%400==0)
    return 1;
    else  
    return 0;
}                                                          //判断是否是闰年
int week1(int year,int month,int day,int i)
{
    if((month>=13||day>=32)||(i==0&&month==2&&day>=29))
    { 
        cout<<"输入错误.";
        day=0;
    }                                                     /*假如输入的月大于13或日大于29,或者不是闰年的情况下输入2月29号,输出错误,同时把day值变为0*/
    switch(month)
    {
        case 2:if(day>=30) 
        { 
        cout<<"输入错误.";
        day=0;
        }                             //假如是2月,日大于30,输出错误,day变为0
        else day+=31;
        break;
        case 3:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                               //假如是3月,日大于31,输出错误,day变为0
        else day+=31+29;
        break;
        case 4:if(day>=30) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                  //假如是4月,日大于30,输出错误,day变为0
        else day+=31+29+31;
        break;
        case 5:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                             //假如是5月,日大于31,输出错误,day变为0
        else day+=31+29+31+30;
        break;
        case 6:if(day>=30) 
        { 
        cout<<"输入错误.";
        day=0;
        }                            //假如是6月,日大于30,输出错误,day变为0
        else day+=31+29+31+30+31;
        break;
        case 7:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                            //假如是7月,日大于31,输出错误,day变为0
        else day+=31+29+31+30+31+30;
        break;
        case 8:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                 //假如是8月,日大于31,输出错误,day变为0
        else day+=31+29+31+30+31+30+31;
        break;
        case 9:if(day>=30) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                  //假如是9月,日大于30,输出错误,day变为0
        else day+=31+29+31+30+31+30+31+31;
        break;
        case 10:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                  //假如是10月,日大于31,输出错误,day变为0
        else day+=31+29+31+30+31+30+31+31+30;
        break;
        case 11:if(day>=30) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                  //假如是11月,日大于30,输出错误,day变为0
        else day+=31+29+31+30+31+30+31+31+30+31;
        break;
        case 12:if(day>=31) 
        { 
        cout<<"输入错误.";
        day=0;
        }                                  //假如是12月,日大于31,输出错误,day变为0
        else day+=31+29+31+30+31+30+31+31+30+31+30;
        break;
        default:break;
    }
    if(month>=3&&i==0) 
                day-=1;                     //不是闰年,大于三月的情况下,比闰年小于1
        int week;
        if(day!=0)  week=(year-1)+int((year-1)*0.1*10/4)-int((year-1)*0.1*10/100)+int((year-1)*0.1*10/400)+day;
        else week=0;
        return week;
        }                             
void outputweek(int week)
    {
         cout<<year<<"年"<<month<<"月"<<day<<"日是";
int w;
    if(week!=0&&day!=0) {
w=week%7;
switch(w)
{
    case 1:cout<<"星期一"<<endl;  break;    
    case 2:cout<<"星期二"<<endl;  break;
    case 3:cout<<"星期三"<<endl;  break;
    case 4:cout<<"星期四"<<endl;  break;
    case 5:cout<<"星期五"<<endl;  break;
    case 6:cout<<"星期六"<<endl;  break;
    case 0:cout<<"星期日"<<endl;  break;
    default:break;
    }
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    不存在的天数也能算出星期几,哪地方错啦?(给但day值为什么不变化?)

回复列表 (共4个回复)

沙发

长期寻求网站入侵人员,拿欧美站,本人自己懂编程写木马,现在差一个网站入侵人员合作目前编写出来的网马大概种马率在40-50左右,而且是12合1体积在20K超高质量网马国内没几个人有能力编写有意者联系QQ25498276详谈

板凳


太长了
[em10]

3 楼

说说是什么问题把!
太长了,还没有注释

4 楼

if((month>=13||day>=32)||(i==0&&month==2&&day>=29))
这句话运算符优先级没考虑,逻辑混乱。加几个括号,改成
    if( ( (month>13) || (day>32) )|| ((i==0)&&(month==2)&&(day>=29))) 试试看
还有在switch的时候没考虑不是闰年但是输入2月29号的问题。

我来回复

您尚未登录,请登录后再回复。点此登录或注册