我写了个好麻烦的代码,运行失败找不到原因

来源:4-17 switch与if语句的应用

heifo

2019-10-29 15:46

#include <stdio.h>
int main()
{
    /* 定义需要计算的日期 */
    int year = 2008;
    int month = 8;
    int day = 8;
     int result;
     int temporary;
switch(year%4)
{
    case 0:
        result+=1;
        if(month>2||month<8);
        {
           
            if(month%2==0);
            {
                result+=month/2*31+(month/2-1)*30+28;
                printf("result");
            }
            else
            {
                result+=(month/2+1)*31+(month/2-1)30+28;
                printf("result");
            }
        }
        else if(month<2||month>0)
        {
            result+=31;
            printf("result");
        }
        else if(month==2)
        {
            result+=31+28;
             printf("result");
        }
        else if(month>=8)
        {  
           
            month-7=temporary;
           
            result+=(month/2+1)*31+(month/2-1)30+28;
           
              if(temporary%2==0)
               {
                result+=temporary/2*31+(temporary/2-1)*30+28;
                 printf("result");
               }
               else
               {
                result+=(temporary/2+1)*31+(temporary/2-1)30+28;
                 printf("result");
               }
        }
   
   
   
   
    default:
    printf("%s\n"," 我失败了");

}

 return 0;
}


写回答 关注

2回答

  • heifo
    2019-10-29 17:20:23

    修改后

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
        /* 定义需要计算的日期 */
        int year = 2008;
        int month = 8;
        int day = 8;
         int result=0;
         int temporary=0;
    switch(year%4)
    {
        case 0:
            result+=1;
            if(month>2||month<8)
            {

                if(month%2==0)
                {
                    result+=month/2*31+(month/2-1)*30+28+day;
                    printf("%d",result);
                    break;
                }
                else
                {
                    result+=(month/2+1)*31+(month/2-1)*30+28+day;
                    printf("%d",result);
                    break;
                }
            }
            else if(month<2||month>0)
            {
                result+=31+day;
                printf("result");
                break;
            }
            else if(month==2)
            {
                result+=31+28+day;
                 printf("result");
                 break;
            }
            else if(month>=8)
            {
                month-=7;
               temporary=month;
               month+=7;

                result+=((month/2+1)*31+(month/2-1)*30+28)+day;

                  if(temporary%2==0)
                   {
                    result+=temporary/2*31+(temporary/2-1)*30+28+day;
                     printf("result");
                     break;
                   }
                   else
                   {
                    result+=(temporary/2+1)*31+(temporary/2-1)*30+28+day;
                     printf("result");break;
                   }
            }
            else
            {
            printf("%s\n","这里什么都没有");
            }

        default:
        printf("%s\n"," 母鸡啊");

    }


     return 0;
    }


  • heifo
    2019-10-29 17:16:09

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
        /* 定义需要计算的日期 */
        int year = 2008;
        int month = 8;
        int day = 8;
         int result=0;
         int temporary=0;
    switch(year%4)
    {
        case 0:
            result+=1;
            if(month>2||month<8)
            {

                if(month%2==0)
                {
                    result+=month/2*31+(month/2-1)*30+28+day;
                    printf("%d",result);
                    break;
                }
                else
                {
                    result+=(month/2+1)*31+(month/2-1)*30+28+day;
                    printf("%d",result);
                    break;
                }
            }
            else if(month<2||month>0)
            {
                result+=31+day;
                printf("result");
                break;
            }
            else if(month==2)
            {
                result+=31+28+day;
                 printf("result");
                 break;
            }
            else if(month>=8)
            {
                month-=7;
               temporary=month;
               month+=7;

                result+=((month/2+1)*31+(month/2-1)*30+28)+day;

                  if(temporary%2==0)
                   {
                    result+=temporary/2*31+(temporary/2-1)*30+28+day;
                     printf("result");
                     break;
                   }
                   else
                   {
                    result+=(temporary/2+1)*31+(temporary/2-1)*30+28+day;
                     printf("result");break;
                   }
            }
            else
            {
            printf("%s\n","这里什么都没有");
            }

        default:
        printf("%s\n"," 母鸡啊");

    }


     return 0;
    }


C语言入门

C语言入门视频教程,带你进入编程世界的必修课-C语言

926028 学习 · 20793 问题

查看课程

相似问题