| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 385 人关注过本帖
标题:急!请高手帮我一下
只看楼主 加入收藏
月中人
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-28
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:4 
急!请高手帮我一下
帮我我看看下面这个程序,我调试不出来。只好求高手与大侠了
#include <stdio.h>

   #define   Sunday      0
   #define   Monday      1
   #define   Tuesday     2
   #define   Wednesday   3
   #define   Thursday    4
   #define   Friday      5
   #define   Saturday    6
   void GiveInstructions(void);
   int GetYearFromUser(void);
   void PrintCalendar(int year);
   void PrintCalendarMonth(int month,int year);
   void IndentFirstLine(int weekday);
   int MonthDays(int month,int year);
   int FirstDayofMonth(int month,int year);
    string MonthName(int month);
   bool IsLeapYear(int year);
void main()
{
   int year;
   GiveInstructions();
   GetYearFromUser();
   PrintCalendar();

}
   void GiveInstructions(void){
       printf("This program dispalys a calendar for a full.\n");
       printf("year.This year must be not before 1990");
   }
   int GetYearFromUser(void){
       int year;
       while(TURE){
           printf("Please enter the year:");
           scanf("%d",&year);
           if(year>1990)
           return(year);
           printf("The year must be at least 1990");
       }
   }
   void PrintCalendar(int year){
       int month;
       for(month=1;month<=12;month++){
           PrintCalendarMonth(month,year);   
       }
       printf("\n");
   }
   void PrintCalendarMonth(int month,int year){
       int weekday,nDays,day;
       printf("     %s %d\n",MonthName(month),year);
       printf(" Su Mo Tu We Th Fr Sa\n");
       nDays=MonthDays(int month,int year);
       weekday=FirstDayofMonth(int month,int year);
       IndentFirstLine(weekday);
       for(day=1;day<=nDay;day++){
           printf(" %2d",day);
           if(weekday==Saturday)
           printf("\n");
           weekday=(weekday+1)%7;
       }
           if(weekday!=Sanday)
           printf("\n");
   }
   void IndentFirstLine(int weekday){
       int i;
       for(i=0;i<weekday;i++)
       printf("   ");
   }
   int MonthDays(int month,int year){
       switch(month){
           case 2;
           if(IsLeapYear(year))
           return(29);
           return(28);
           case 1:case 3:case 5:case 7:case 8:case 10:case 12:
           return(31);
           default return(30);
       }
   }
   int FirstDayofMonth(int month,int year){
       weekday=Monday;
       for(i=1990;i<year;i++){
           weekday=(weekday+365)%7;
           if(IsLeapYear)
           weekday=(weekday+1)%7;
       }
       for(i=1;i<month;i++){
           weekday=(weekday+MonthDays(month,year))%7;
       }
       return(weekday);
   }
   bool IsLeapYear(int year){
       return((year%4==0)&&(year%100!=0)||(year%400==0));
   }
   string MonthName(int month){
       switch(manth){
           case 1:  return  ("January");
           case 2:  return  ("Febrruary");
           case 3:  return  ("March");
           case 4:  return  ("April");
           case 5:  return  ("May");
           case 6:  return  ("june");
           case 7:  return  ("july");
           case 8:  return  ("August");
           case 9:  return  ("September");
           case 10: return  ("October");
           case 11: return  ("Noveber");
           case 12: return  ("december");
       }
   }
 
搜索更多相关主题的帖子: include 
2011-10-28 17:55
xp0213
Rank: 7Rank: 7Rank: 7
来 自:湖北武汉
等 级:黑侠
威 望:1
帖 子:222
专家分:524
注 册:2011-10-26
收藏
得分:10 
程序可读性很差!
2011-10-28 20:47
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:10 
程序代码:
#include <stdio.h>
#include <string.h>
#define   Sunday      0
#define   Monday      1
#define   Tuesday     2
#define   Wednesday   3
#define   Thursday    4
#define   Friday      5
#define   Saturday    6
void GiveInstructions(void);
int GetYearFromUser(void);
void PrintCalendar(int year);
void PrintCalendarMonth(int month,int year);
void IndentFirstLine(int weekday);
int MonthDays(int month,int year);
int FirstDayofMonth(int month,int year);
char * MonthName(int month);
bool IsLeapYear(int year);
void main()
{
    int year;
    GiveInstructions();
    GetYearFromUser();
    scanf("%d",&year);////
    PrintCalendar(year);////

}
void GiveInstructions(void)
{
    printf("This program dispalys a calendar for a full.\n");
    printf("year.This year must be not before 1990");
}
int GetYearFromUser(void)
{
    int year;
    while(true)/////
    {
        printf("Please enter the year:");
        scanf("%d",&year);
        if(year>1990)
            return(year);
        printf("The year must be at least 1990");
    }
}
void PrintCalendar(int year)
{
    int month;
    for(month=1;month<=12;month++)
    {
        PrintCalendarMonth(month,year);  
    }
    printf("\n");
}
void PrintCalendarMonth(int month,int year)
{
    int weekday,nDays,day;
    printf("     %s %d\n",MonthName(month),year);
    printf(" Su Mo Tu We Th Fr Sa\n");
    nDays=MonthDays(month,year);//////
    weekday=FirstDayofMonth(month,year);/////
    IndentFirstLine(weekday);
    for(day=1;day<=nDays;day++)
    {////
        printf(" %2d",day);
        if(weekday==Saturday)
            printf("\n");
        weekday=(weekday+1)%7;
    }
    if(weekday!=Sunday)/////
        printf("\n");
}
void IndentFirstLine(int weekday)
{
    int i;
    for(i=0;i<weekday;i++)
        printf("   ");
}
int MonthDays(int month,int year)
{
    switch(month)
    {
    case 2://///
            if(IsLeapYear(year))
                return(29);
            return(28);
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        return(31);
    default://////
        return(30);
    }
}
int FirstDayofMonth(int month,int year)
{
    int weekday=Monday;
    int i;////
    for(i=1990;i<year;i++)
    {
        weekday=(weekday+365)%7;
        if(IsLeapYear(year))
            weekday=(weekday+1)%7;
    }
    for(i=1;i<month;i++)
    {
        weekday=(weekday+MonthDays(month,year))%7;
    }
    return(weekday);
}
bool IsLeapYear(int year)
{
    return((year%4==0)&&(year%100!=0)||(year%400==0));
}
char * MonthName(int month)
{
    switch(month)////
    {
    case 1:  return  ("January");
    case 2:  return  ("Febrruary");
    case 3:  return  ("March");
    case 4:  return  ("April");
    case 5:  return  ("May");
    case 6:  return  ("june");
    case 7:  return  ("july");
    case 8:  return  ("August");
    case 9:  return  ("September");
    case 10: return  ("October");
    case 11: return  ("Noveber");
    case 12: return  ("december");
    default:return ("Error");
    }
}
收到的鲜花
  • 月中人2011-10-29 18:39 送鲜花  3朵   附言:感谢你的修改
2011-10-29 00:57
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:0 
回复 3楼 laznrbfe
语法没有错误了,但是输出的和实际的日历不一致,你的函数有问题。
2011-10-29 00:57
月中人
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-28
收藏
得分:0 
谢谢各位赏光   我是一个C菜鸟  请高手多指教
2011-10-29 18:35
快速回复:急!请高手帮我一下
数据加载中...
 
   



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

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