CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

两段计算年龄的代码,出现问题,大家给帮忙改改,小弟是在不知道问题在哪里,跪谢!

楼主bylmy()2004-12-01 05:12:36 在 C/C++ / C语言 提问

#include   <time.h>  
  #include   <stdio.h>  
  #include   <dos.h>  
   
   
  void   main()  
  {  
          int   year,month,day;  
          struct   date{  
  long   year,mon,day;};  
  struct   date   *yourbirthd,   *nowd;  
  struct   tm{};  
          struct   tm   yourbirtht,   nowt;  
   
          long   yourbrith,now;  
          long   resultt;  
          double   result;  
   
          printf("\nplease   input   your   birth   date   (year,month,day):\n");  
          scanf("%d,%d,%d",&year,&month,&day);                          
     
    22)       getdate(&nowd);  
    23)       gettime(nowt);  
          yourbirthd->year=year;  
          yourbirthd->day=day;  
          yourbirthd->mon=month;  
   
    28)       yourbirth=dostounix(yourbirthd,yourbirtht);  
          now=dostounix(nowd,nowt);  
          resultt=difftime(yourbirthd,nowd);  
          result=resultt/(24*60*60);  
          printf("\nYou   hava   come   this   world   for   %d   days\n");    
  }  
  以上这段代码在VC++中编译出现以下错误,请问如何改正?  
  --------------------Configuration:   2.2   -   Win32   Debug--------------------  
  Compiling...  
  2.2.cpp  
  E:\c\cpp2\2.2.cpp(22)   :   error   C2065:   'getdate'   :   undeclared   identifier  
  E:\c\cpp2\2.2.cpp(23)   :   error   C2065:   'gettime'   :   undeclared   identifier  
  E:\c\cpp2\2.2.cpp(28)   :   error   C2065:   'yourbirth'   :   undeclared   identifier  
  E:\c\cpp2\2.2.cpp(28)   :   error   C2065:   'dostounix'   :   undeclared   identifier  
  Error   executing   cl.exe.  
   
  2.2.obj   -   4   error(s),   0   warning(s) 问题点数:0、回复次数:5Top

1 楼bylmy()回复于 2004-12-01 05:13:26 得分 0

为什么我的这一段代码算出来是个负数??看不出毛病在哪里,请大家帮忙指正,谢谢!!  
  for(int   i=year2+1;   i<year1;   i++){  
        if(i%400==0||(i%4==0&&i%100!=0))   /*判断是不是闰年*/  
          sum3=sum3+366;  
        else  
          sum3=sum3+365;  
  }  
  其中year2,year1是两个整型变量,用来输入两个年份。如1977,2004  
  结果出来都是一样的,-864848593,很奇怪。Top

2 楼infini(nebula)回复于 2004-12-01 06:50:20 得分 0

sum3没有初始化吧?Top

3 楼bylmy()回复于 2004-12-01 07:18:30 得分 0

程序修改后,编译后一个错误,说我的birth(打*处)未定义,可是我不是定义了么,怎么回事呢?  
   
  #include   <time.h>  
  #include   <stdio.h>  
  #include   <dos.h>  
   
  void   main()  
  {  
          int   year,month,day;  
          struct   date{  
          long   year,mon,day;  
          }yourbirthd,   nowd;  
          struct   time   yourbirtht,nowt;  
   
          long   brith,now;  
          double   result;  
   
          printf("\nplease   input   your   birth   date   (year,month,day):\n");  
          scanf("%d,%d,%d",&year,&month,&day);                          
     
          getdate(&nowd);  
          gettime(&nowt);  
          yourbirthd.year=year;  
          yourbirthd.day=day;  
          yourbirthd.mon=month;  
   
  *         birth   =   dostounix(&yourbirthd,&yourbirtht);  
          now   =   dostounix(&nowd,&nowt);  
          result=difftime(birth,now)/(24*60*60);  
          printf("\nYou   hava   come   this   world   for   %d   days\n",   result);    
  }Top

4 楼bylmy()回复于 2004-12-01 07:21:13 得分 0

是sum3没有初始化,现在已经正确了,谢谢。Top

5 楼bylmy()回复于 2004-12-01 07:55:25 得分 0

现在已经修改后,编译通过,可是运行时,输入生日后,回车没显示结果,是怎么回事?大家给看看是哪里有问题呢?  
   
  #include   <time.h>  
  #include   <stdio.h>  
  #include   <dos.h>  
   
  void   main()  
  {  
          int   year,month,day;  
          struct   date{  
          long   year,mon,day;  
          }yourbirthd,   nowd;  
          struct   time   yourbirtht,nowt;  
   
          long   brith;  
          long   now;  
          double   result;  
   
          printf("\nplease   input   your   birth   date   (year,month,day):\n");  
          scanf("%d,%d,%d",&year,&month,&day);                          
     
          getdate(&nowd);  
          gettime(&nowt);  
          yourbirthd.year=year;  
          yourbirthd.day=day;  
          yourbirthd.mon=month;  
   
          birth   =   dostounix(&yourbirthd,&yourbirtht);  
          now   =   dostounix(&nowd,&nowt);  
          result=difftime(birth,now)/(24*60*60);  
          printf("\nYou   hava   come   this   world   for   %d   days\n",   result);    
  }  
  Top

相关问题

  • 请高人帮我改改这个代码!!!谢谢
  • 利用VB如何锁定计算机,例如win2000,请代码示例,谢
  • 帮我改改代码!
  • 请问,这段代码应该怎么改,就可以计算若干列的统计值呢?谢谢!!!
  • 高分求两段代码!文件大小计算和影像文件上传,谢谢啦
  • 哪位手里有单向MD5 hash计算 的源代码共享一下,谢谢了
  • 给我一计算器的源代码
  • 如何计算代码行数?
  • 计算阴历的函数原代码
  • linux下的bc计算器---源代码????????

关键词

  • 代码
  • cpp
  • date
  • yourbirthd
  • nowd
  • nowt
  • yourbirtht
  • dostounix
  • birth
  • year

得分解答快速导航

  • 帖主:bylmy

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo