为了账号安全,请及时绑定邮箱和手机立即绑定

error C2196: case 值“1”已使用 ====了

error C2196: case 值“1”已使用 ====了

C
慕粉18341035298 2016-07-01 15:36:50
#include <stdafx.h>int main(){ int year = 2008, month = 8, day = 8, b = 0; for (; 1 <= month; month--) {  switch (month)  {  case 1 || 3 || 5 || 7 || 8 || 10 || 12:   b = b + 31;   break;  case 2:   if (year % 4 == 0 && year % 100 !=0 || year % 400 == 0)    b = b + 29;   else    b = b + 28;   break;  case 4||6||9||11:    b = b + 30;    break;  } } printf("%d", b + day); return 0;}
查看完整描述

1 回答

已采纳
?
OuBa

TA贡献6条经验 获得超5个赞

#include <stdafx.h>
int main()
{
    int year = 2008;
    int month = 8; 
    int day = 8;
    int b = 0;
    
    for (; 1 <= month; month--)
    {
        switch (month)
        {
             case 1:
             case 3:
             case 5:
             case 7:
             case 8:
             case 10:
             case 12:
             {
                 b = b + 31;
                 break;
             }
             case 2:
             {
                  if (year % 4 == 0 && year % 100 !=0 || year % 400 == 0)
                  {
                      b = b + 29;
                  } 
                  else
                  {
                      b = b + 28;
                  }
                  break;
             }
             case 4:
             case 6:
             case 9:
             case 11:
             {
                  b = b + 30;
                  break;
             }
         }
     }
     printf("%d\n", b + day);
     return 0;
}


查看完整回答
反对 回复 2016-07-01
  • 1 回答
  • 0 关注
  • 1824 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信