标题:求教,很简单的一个万年历程序运行成功,但是输入选项2,出现.exe' has exi ...
只看楼主
RhsR
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-1-4
结帖率:100%
已结贴  问题点数:20 回复次数:3 
求教,很简单的一个万年历程序运行成功,但是输入选项2,出现.exe' has exited with code 0 (0x0).
程序代码:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <process.h>
int day_s(); 
int year_s(); 
int week_s(); 
void output_month(); 
void menu(); 
void output_year(); 
int year,month; 
int main() 
{ 

 SYSTEMTIME time;

 GetSystemTime(&time);//获取当前系统的时间
 year=time.wYear;

 month=time.wMonth;

 printf("\t\t今天是公元%d年%d月%d日\n\n",time.wYear,time.wMonth,time.wDay);

 output_month(); 

 menu(); 

 return 0;
}
int Windows()
{ 

 printf("请输入年月以打印该月日历!\n");

 printf("年:");

 scanf("%d",&year);

 printf("月:");

 scanf("%d",&month);

 system("cls");

 printf("\t\t公元%d年\n",year);

 output_month(); 

 menu(); 

 return 0;
}
int day_s() 
{ 

 switch(month) 

 { 

 case 1: 

 case 3: 

 case 5: 

 case 7: 

 case 8: 

 case 10: 

 case 12:return 31;break; 

 case 4: 

 case 6: 

 case 9: 

 case 11:return 30;break; 

 case 2:
  {
   if(year%4==0&&year%100!=0||year%400==0) return 29; 
   else   return 28;
   break;
  }

 } 
}
int year_s() 
{ 

 int s=1; 

 switch(month-1) 

 { 

 case 11:s+=30; 

 case 10:s+=31; 

 case 9:s+=30; 

 case 8:s+=31; 

 case 7:s+=31; 

 case 6:s+=30; 

 case 5:s+=31; 

 case 4:s+=30; 

 case 3:s+=31; 

 case 2:
  {
   if(year%4==0&&year%100!=0||year%400==0)s+=29; 
   else s+=28; 
  }

 case 1:s+=31; 

 } 

 return s; 
}
int week_s() 
{ 

 int s=1,n; 

 n=(year-1)%400; 

 for(int i=1;i<=n;i++) 

 { 
  if(year%4==0&&year%100!=0||year%400==0) 
   s+=2; 
  else s+=1; 

 } 

 s+=year_s(); 

 s%=7; 

 return s; 
}
void output_month() 
{ 

 int week,day,i; 

 printf("\t\t公元%d月\n",month);

 printf("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n"); 

 day=day_s(); 

 week=week_s(); 

 for(i=1;i<=week;i++)

 {
  printf(" \t"); 

 }

 for(i=1;i<=day;i++) 

 { 
  printf("%d",i);
  if((i+week)%7==0) printf("\n");
  else printf("\t");

 } 

 for(int j=1;j<=42-week-i;j++)

 {
  printf("\t");

 }

 printf("\n\n");
}
void output_year() 
{ 

 printf("\t\t公元%d年\n",year);

 for(int i=1;i<=12;i++) 

 { 
  month=i; 
  output_month(); 

 } 

 printf("1查看下年\n");

 printf("2查看上年\n");

 printf("3重新输入年月\n");

 printf("0退出\n");

 printf("请选择:");

 int n; 

 scanf("%d",&n);
    system("cls"); 

 switch(n) 

 { 

 case 1:year+=1;output_year();break; 

 case 2:year-=1;output_year();break; 

 case 3:main();break; 

 case 0:;break; 

 }
} 
void menu() 
{ 

 printf("1查看下个月\n");

 printf("2查看上个月\n");

 printf("3查看本年全部日历\n");

 printf("4重新输入年月\n");

 printf("0退出\n");

 printf("请选择:");

 int n; 

 scanf("%d",&n);
    system("cls"); 

 switch(n) 

 {

 case 1:
  {
   if(month+1==13)
   {
    year+=1;
    month=1;
   } 
   else month+=1;
   printf("\t\t公元%d年\n",year);
   output_month(); 
   menu(); 
   break; 
  }

 case 2:
  {
   if(month-1==0)
   {
    year-=1;month=12;
   }
   else
   {
    month-=1; 
    printf("\t\t公元%d年\n",year);
    output_month(); 
    menu(); 
   }
   break;
  }

 case 3:output_year();break; 

 case 4:Windows();break; 

 case 0:break; 

 } 
}






在任意年份时,当月份为1月时候输入选项2查看上月日历程序闪退,出现has exited with code 0 (0x0).的提示,,,求教
搜索更多相关主题的帖子: 万年历 
2017-01-04 12:13
RhsR
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-1-4
得分:0 
而且现在发现日历和星期对不上,,显示是错误的,,怎么修改,求教
2017-01-04 12:17
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
这是典型的人品问题,只要将代码排版好就能一眼看出

case 2:
    {
        if(month-1==0)
        {
            year-=1;month=12;
        }
        else
        {
            month-=1;
            printf("\t\t公元%d年\n",year);
            output_month();
            menu();
        }
        break;
    }

应该是

case 2:
    {
        if(month-1==0)
        {
            year-=1;month=12;
        }
        else
        {
            month-=1;
        }
        printf("\t\t公元%d年\n",year);
        output_month();
        menu();
        break;
    }
2017-01-04 14:40
RhsR
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-1-4
得分:0 
回复 3楼 rjsp
受教了,谢谢大神,还有一个问题,程序中万年历的星期几和实际的对不上,2017年一月一号应该是星期天,但是显示却是星期四,怎么改??
2017-01-04 14:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-473276-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.992453 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved