注册 登录
编程论坛 VC++/MFC

错在哪?

心爱的远方 发布于 2011-05-30 23:37, 313 次点击
#include<iostream.h>
 struct date
 {
     int mont;
     int day;
     int year;
 }
    tad[][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
    {0,31,289,31,30,31,30,31,31,30,31,30,31}};
 int dofy(struct date *p)
 {
     int k,i,day;
     day=p->day;
     k=p->year%4==0&&p->year%100!=0||p->year%400==0;
     for(i=0;i<p->mont;i++)
        day+=tad[k][i];
     return day;
 }
  void main()
  {
      date sdate;
      cout<<"input the year: ";
      cin>>date.year;
      cout<<"input the month:";
      cin>>date.mont;
      cout<<"input the day: ";
      cin>>date.day;
      cout<<"这是该年的第"<<dofy(&date)<<"天!"<<endl;
  }
3 回复
#2
qq10235692232011-05-31 08:33
tad[][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,289,31,30,31,30,31,31,30,31,30,31}};
一个data结构有3个数据,13个data就有39个数据,知道错了吗?
#3
laznrbfe2011-05-31 21:30
#include<iostream.h>
struct date
{
     int mont;
     int day;
     int year;
};//////////////////////////////分号
    int tad[][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},               /////////////////没有定义数组类型
    {0,31,289,31,30,31,30,31,31,30,31,30,31}};
int dofy(struct date *p)
{
     int k,i,day;
     day=p->day;
     k=p->year%4==0&&p->year%100!=0||p->year%400==0;
     for(i=0;i<p->mont;i++)
        day+=tad[k][i];
     return day;
}
  void main()
  {
      date sdate;
      cout<<"input the year: ";
      cin>>sdate.year;         /////////////结构体名sdata
      cout<<"input the month:";
      cin>>sdate.mont;           /////////////////
      cout<<"input the day: ";
      cin>>sdate.day;                ///////////////
      cout<<"这是该年的第"<<dofy(&sdate)<<"天!"<<endl;
  }
#4
心爱的远方2011-05-31 23:27
感谢各位啦,小弟不甚感激!
1