| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 612 人关注过本帖
标题:新手上路,出现错误,求解?!!!!!
只看楼主 加入收藏
shandongligo
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-5-18
结帖率:33.33%
收藏
已结贴  问题点数:10 回复次数:9 
新手上路,出现错误,求解?!!!!!
   #include<stdio.h>
int H (int x,int y)
{
    int i=1,k=0,sum,b,a;
    do
    {
        if(i%100==0)
            k=k+1;
        else
        {
            if(i%4==0)
                k=k+1;
            else
                i=i+1;
        }
    }
    while(i<x);
    if(x%100==0)
    {
        sum=366*i+365*(x-1)+1;
        switch(y)
        {
        case(1):         b=sum%7;                                               return(b);
        case(2):         a=sum+(y-1)*31;                  b=a%7;                 return(b);
        case(3):         a=sum+(y-1)*31+29;               b=a%7;                 return(b);
        case(4):         a=sum+(y-2)*31+29;               b=a%7;                 return(b);
        case(5):         a=sum+(y-3)*31+(y-4)*30+29;      b=a%7;                 return(b);
        case(6):         a=sum+(y-3)*31+(y-5)*30+29;      b=a%7;                 return(b);
        case(7):         a=sum+(y-4)*31+(y-5)*30+29;      b=a%7;                 return(b);
        case(8):         a=sum+(y-4)*31+(y-6)*30+29;      b=a%7;                 return(b);
        case(9):         a=sum+(y-4)*31+(y-7)*30+29;      b=a%7;                 return(b);
        case(10):        a=sum+(y-5)*31+(y-7)*30+29;      b=a%7;                 return(b);
        case(11):        a=sum+(y-5)*31+(y-8)*30+29;      b=a%7;                 return(b);
        case(12):        a=sum+(y-6)*31+(y-8)*30+29;      b=a%7;                 return(b);
        }
    }
else
{
    if(x%4==0)
    {
        sum=366*i+365*(x-1)+1;
        switch(y)
        {
        case(1):         b=sum%7;                                               return(b);
        case(2):        a=sum+(y-1)*31;                 b=a%7;                 return(b);
        case(3):         a=sum+(y-1)*31+29;               b=a%7;                 return(b);
        case(4):         a=sum+(y-2)*31+29;               b=a%7;                 return(b);
        case(5):         a=sum+(y-3)*31+(y-4)*30+29;      b=a%7;                 return(b);
        case(6):         a=sum+(y-3)*31+(y-5)*30+29;      b=a%7;                 return(b);
        case(7):         a=sum+(y-4)*31+(y-5)*30+29;      b=a%7;                 return(b);
        case(8):         a=sum+(y-4)*31+(y-6)*30+29;     b=a%7;                 return(b);
        case(9):         a=sum+(y-4)*31+(y-7)*30+29;      b=a%7;                 return(b);
        case(10):        a=sum+(y-5)*31+(y-7)*30+29;      b=a%7;                 return(b);
        case(11):        a=sum+(y-5)*31+(y-8)*30+29;      b=a%7;                 return(b);
        case(12):        a=sum+(y-6)*31+(y-8)*30+29;      b=a%7;                 return(b);
        }
    }
    else
    {
        sum=366*i+365*(x-1)+1;
        switch(y)
        {
        case(1):         b=sum%7;                                               return(b);
        case(2):         a=sum+(y-1)*28;                 b=a%7;                 return(b);
        case(3):         a=sum+(y-1)*31+28;               b=a%7;                 return(b);
        case(4):         a=sum+(y-2)*31+28;               b=a%7;                 return(b);
        case(5):         a=sum+(y-3)*31+(y-4)*30+28;      b=a%7;                 return(b);
        case(6):         a=sum+(y-3)*31+(y-5)*30+28;      b=a%7;                 return(b);
        case(7):         a=sum+(y-4)*31+(y-5)*30+28;      b=a%7;                 return(b);
        case(8):         a=sum+(y-4)*31+(y-6)*30+28;      b=a%7;                 return(b);
        case(9):         a=sum+(y-4)*31+(y-7)*30+28;      b=a%7;                 return(b);
        case(10):        a=sum+(y-5)*31+(y-7)*30+28;      b=a%7;                 return(b);
        case(11):        a=sum+(y-5)*31+(y-8)*30+28;      b=a%7;                 return(b);
        case(12):        a=sum+(y-6)*31+(y-8)*30+28;      b=a%7;                 return(b);
        }
    }
}
main();
{
    int a,b,c,k,j,f,d;
    printf("请输入年份");
    scanf("%d",&a);
    printf("请输入月份");
    scanf("%d",&b);
    if(a%100==0)
    {
        switch(b)
    {
        case(1):       d=31;     
        case(2):      d=29;  
        case(3):       d=31;  
        case(4):       d=30;  
        case(5):       d=31;  
        case(6):       d=30;  
        case(7):       d=31;  
        case(8):       d=31;  
        case(9):       d=30;  
        case(10):      d=31;  
        case(11):      d=30;  
        case(12):      d=31;
    }
    }
    else
        {
        if(a%4==0)
        switch(b)
    {
        case(1):       d=31;     
        case(2):       d=29;  
        case(3):       d=31;  
        case(4):       d=30;  
        case(5):       d=31;  
        case(6):       d=30;  
        case(7):       d=31;  
        case(8):       d=31;  
        case(9):       d=30;  
        case(10):      d=31;  
        case(11):      d=30;  
        case(12):      d=31;
    }
        else
        switch(b)
    {
        case(1):       d=31;     
        case(2):       d=28;  
        case(3):       d=31;  
        case(4):       d=30;  
        case(5):       d=31;  
        case(6):       d=30;  
        case(7):       d=31;  
        case(8):       d=31;  
        case(9):      d=30;  
        case(10):      d=31;  
        case(11):      d=30;  
        case(12):      d=31;
    }
        }
    printf("_____________________________________________________");
    printf("   星期一 星期二 星期三 星期四 星期五 星期六 星期日");
    c=H(a,b);
    for(k=1;k<=7*c-1;k++)
       printf(" ");
    for(j=1;j<=d;j++)
    {
       printf("%d",j);
       for(f=1;f<=6;f++)
           printf(" ");
           if(7*a-1+6*(j-1)+3==51)
               printf("\n");
    }
    printf("_____________________________________________________");
}

出现一下错误:
C:\Users\lenovo\Desktop\a.c(153) : fatal error C1004: unexpected end of file found

新手学程序,希望高手指教。
搜索更多相关主题的帖子: 新手上路 include return 
2013-05-18 23:51
燃高
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:67
专家分:140
注 册:2011-12-13
收藏
得分:0 
你在main前面少到一个中括号!!!在编写程序的时候最好中括号一对一起打进去呢!!!这样就不会忘记额!!!!
2013-05-19 00:18
燃高
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:67
专家分:140
注 册:2011-12-13
收藏
得分:0 
你程序是不是把某年的某月的日子输出来嗯!!!!
2013-05-19 00:20
遮天云
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
注 册:2010-6-1
收藏
得分:0 
一楼说出了一点错后,还有一个就是楼主main()后面多加了一个分号
2013-05-19 00:29
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
case 要加 break


[fly]存在即是合理[/fly]
2013-05-19 01:20
YJ_Hao
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:215
专家分:609
注 册:2013-3-22
收藏
得分:0 
错误不少!case(10):有这样的?
2013-05-19 06:05
我叫沃恩
Rank: 12Rank: 12Rank: 12
来 自:Asia
等 级:贵宾
威 望:10
帖 子:1234
专家分:3865
注 册:2013-3-29
收藏
得分:0 
建议楼主多看书!!

因为我是菜鸟,所以应该被骂! 细节+坚持=成功!
2013-05-19 07:12
YJ_Hao
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:215
专家分:609
注 册:2013-3-22
收藏
得分:10 
给你正确的对照下!!是根据你的修改的!
程序代码:
#include<stdio.h>
int H(int x,int y)
{
    int i=0,k=0,sum,b,a,j=1;
    while(j<x)
    {
        if(j%400==0)
            k=k+1;
        else
        {
            if(j%4==0 && j%100!=0)
                k=k+1;
            else
                i=i+1;
        }
        j++;
    }
    if(x%400==0)
    {
        sum=365*i+366*k+1;
        switch(y)
        {
        case 1:         b=sum%7;                                               return b;
        case 2:         a=sum+(y-1)*31;                  b=a%7;                 return b;
        case 3:         a=sum+(y-1)*31+29;               b=a%7;                 return b;
        case 4:         a=sum+(y-2)*31+29;               b=a%7;                 return b;
        case 5:         a=sum+(y-3)*31+(y-4)*30+29;      b=a%7;                 return b;
        case 6:         a=sum+(y-3)*31+(y-5)*30+29;      b=a%7;                 return b;
        case 7:         a=sum+(y-4)*31+(y-5)*30+29;      b=a%7;                 return b;
        case 8:         a=sum+(y-4)*31+(y-6)*30+29;      b=a%7;                 return b;
        case 9:         a=sum+(y-4)*31+(y-7)*30+29;      b=a%7;                 return b;
        case 10:        a=sum+(y-5)*31+(y-7)*30+29;      b=a%7;                 return b;
        case 11:        a=sum+(y-5)*31+(y-8)*30+29;      b=a%7;                 return b;
        case 12:        a=sum+(y-6)*31+(y-8)*30+29;      b=a%7;                 return b;
        }
    }
    else
    {
        if(x%4==0 && i%100!=0)
        {
            sum=365*i+366*k+1;
            switch(y)
            {
            case 1:         b=sum%7;                                               return b;
            case 2:        a=sum+(y-1)*31;                 b=a%7;                 return b;
            case 3:         a=sum+(y-1)*31+29;               b=a%7;                 return b;
            case 4:         a=sum+(y-2)*31+29;               b=a%7;                 return b;
            case 5:         a=sum+(y-3)*31+(y-4)*30+29;      b=a%7;                 return b;
            case 6:         a=sum+(y-3)*31+(y-5)*30+29;      b=a%7;                 return b;
            case 7:         a=sum+(y-4)*31+(y-5)*30+29;      b=a%7;                 return b;
            case 8:         a=sum+(y-4)*31+(y-6)*30+29;     b=a%7;                 return b;
            case 9:         a=sum+(y-4)*31+(y-7)*30+29;      b=a%7;                 return b;
            case 10:        a=sum+(y-5)*31+(y-7)*30+29;      b=a%7;                 return b;
            case 11:        a=sum+(y-5)*31+(y-8)*30+29;      b=a%7;                 return b;
            case 12:        a=sum+(y-6)*31+(y-8)*30+29;      b=a%7;                 return b;
            }
        }
        else
        {
            sum=365*i+366*k+1;
            switch(y)
            {
            case 1:         b=sum%7;                                               return b;
            case 2:         a=sum+(y-1)*31;                 b=a%7;                 return b;
            case 3:         a=sum+(y-1)*31+28;               b=a%7;                 return b;
            case 4:         a=sum+(y-2)*31+28;               b=a%7;                 return b;
            case 5:         a=sum+(y-3)*31+(y-4)*30+28;      b=a%7;                 return b;
            case 6:         a=sum+(y-3)*31+(y-5)*30+28;      b=a%7;                 return b;
            case 7:         a=sum+(y-4)*31+(y-5)*30+28;      b=a%7;                 return b;
            case 8:         a=sum+(y-4)*31+(y-6)*30+28;      b=a%7;                 return b;
            case 9:         a=sum+(y-4)*31+(y-7)*30+28;      b=a%7;                 return b;
            case 10:        a=sum+(y-5)*31+(y-7)*30+28;      b=a%7;                 return b;
            case 11:        a=sum+(y-5)*31+(y-8)*30+28;      b=a%7;                 return b;
            case 12:        a=sum+(y-6)*31+(y-8)*30+28;      b=a%7;                 return b;
            }
        }
    }
}
main()
{
    int a,b,c,k,j,f,d,m;
    printf("请输入年份");
    scanf("%d",&a);
    printf("请输入月份");
    scanf("%d",&b);
    if(a%400==0)
    {
        switch(b)
        {
        case 1:       d=31;  break;   
        case 2:      d=29;  break;
        case 3:       d=31;  break;
        case 4:       d=30;  break;
        case 5:       d=31;  break;
        case 6:       d=30;  break;
        case 7:       d=31;  break;
        case 8:       d=31;  break;
        case 9:       d=30;  break;
        case 10:      d=31;  break;
        case 11:      d=30;  break;
        case 12:      d=31;break;
        }
    }
    else
    {
        if(a%4==0 && a%100!=0)
        {
            switch(b)
            {
            case 1:       d=31; break;   
            case 2:       d=29;  break;
            case 3:       d=31;  break;
            case 4:       d=30;  break;
            case 5:       d=31;  break;
            case 6:       d=30;  break;
            case 7:       d=31;  break;
            case 8:       d=31;  break;
            case 9:       d=30;  break;
            case 10:      d=31;  break;
            case 11:      d=30;  break;
            case 12:      d=31;break;
            }
        }
        else
        {
            switch(b)
            {
            case 1:       d=31;   break; 
            case 2:       d=28;  break;
            case 3:       d=31;  break;
            case 4:       d=30;  break;
            case 5:       d=31;  break;
            case 6:       d=30;  break;
            case 7:       d=31;  break;
            case 8:       d=31;  break;
            case 9:       d=30;  break;
            case 10:      d=31;  break;
            case 11:      d=30;  break;
            case 12:      d=31;break;
            }
        }
    }
    printf("_____________________________________________________\n");
    printf("   星期一 星期二 星期三 星期四 星期五 星期六 星期日\n");
    c=H(a,b);
    c = (c==0)?7:c;
    for(k=1;k<=7*c-1;k++)
        printf(" ");
    for(j=1;j<=d;j++)
    {
        printf("%d",j);
        m = (j>=9)?5:6;
        for(f=1;f<=m;f++)
        {
            printf(" ");
            if((j+c-1)%7==0 && f==3)
                printf("\n   ");
        }
    }
    printf("\n_____________________________________________________\n");
}
收到的鲜花
  • shandongligo2013-05-19 17:23 送鲜花  3朵   附言:我很赞同
2013-05-19 07:56
shandongligo
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-5-18
收藏
得分:0 
回复 8楼 YJ_Hao
问题解决,非常感谢!!!
2013-05-19 17:24
scrooper
Rank: 2
来 自:杭州
等 级:论坛游民
帖 子:13
专家分:21
注 册:2012-7-10
收藏
得分:0 
我觉得楼主提问之前应该先说自己的代码是用来干什么的
2013-05-19 20:37
快速回复:新手上路,出现错误,求解?!!!!!
数据加载中...
 
   



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

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