| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
大量收QQ微信精准粉/交友粉,非诚勿扰千里之行 始于足下
共有 400 人关注过本帖
标题:请教一下,这个关于switch的语句~
只看楼主 加入收藏
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
结帖率:50%
  已结贴   问题点数:5  回复次数:7   
请教一下,这个关于switch的语句~
要求输入年份和月份 得出本月天数
#include<stdio.h>
void main()
{
    int year,month;
    printf("input year and month:");
    scanf("%d%d",&year,&month);
     if(month==2)
     {
         if((year%4==0&&year%100!==0)||(year%400==0))
             printf("the days of %d of %d is 29",year,month");
         else printf("the days of %d of %d is 28",year,month");
     }
 switch(month)
     {
         case 1:
         case 3:
         case 5:
         case 7:
         case 8:
         case 10:
         case 12:prtinf("the days of %d of %d is 31",year,month);break;
         case 4:
         case 6:
         case 8:
         case 11:prtinf("the days of %d of %d is 30",year,month);break;
         default:printf("error input!\n");
     }
}
10 errors,1 warning      
不太清楚错在哪里了 请指教qaq
2018-04-15 16:35
ab1412
Rank: 7Rank: 7Rank: 7
来 自:M78星球
等 级:黑侠
威 望:3
帖 子:100
专家分:535
注 册:2018-3-15
  得分:5 
程序代码:
#include<stdio.h>
 void main()
 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      if(month==2)
      {
          if((year%4==0&&year%100!=0)||(year%400==0))
              printf("the days of %d of %d is 29",year,month);
          else printf("the days of %d of %d is 28",year,month);
      }
  switch(month)
      {
          case 1:
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:printf("the days of %d of %d is 31",year,month);break;
          case 4:
          case 6:
          case 9:
          case 11:printf("the days of %d of %d is 30",year,month);break;
          default:printf("error input!\n");
  }
 }



错的地方有点多,我就不一一说了,帮你改好了自己看吧

printf("萌新一枚,请多指教");
2018-04-15 16:57
a451410
Rank: 2
等 级:论坛游民
帖 子:20
专家分:28
注 册:2018-3-4
  得分:0 
printf不是prtinf  基本的输出函数要记清楚!  !=(不等于要这样写),不能写成!==   
基本的单词要记住。
2018-04-15 17:05
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
  得分:0 
回复 2楼 ab1412
谢谢您哈~
2018-04-15 17:48
只剩云淡风轻
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-4-15
  得分:0 
回复 3楼 a451410
一时疏忽。。Thanks♪(・ω・)ノ蟹蟹~
2018-04-15 17:49
欧讷河文
Rank: 2
等 级:论坛游民
帖 子:15
专家分:12
注 册:2018-3-28
  得分:0 
回复 2楼 ab1412
你这个输2月份有问题的  不是天数问题 是后面跟着error input!
2018-04-16 18:24
孤傲晴天
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-4-9
  得分:0 
最终版:

#include<stdio.h>
 void main()
 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      if(month==2)
      {
          if((year%4==0&&year%100!=0)||(year%400==0))
              printf("the days of %d of %d is 29",year,month);
          else printf("the days of %d of %d is 28",year,month);
      }
    else
    {
      switch(month)
          {
              case 1:
              case 3:
              case 5:
              case 7:
              case 8:
              case 10:
              case 12:printf("the days of %d of %d is 31",year,month);break;
              case 4:
              case 6:
              case 9:
              case 11:printf("the days of %d of %d is 30",year,month);break;
              default:printf("error input!\n");
      }
    }
 }
2018-04-16 21:46
nosnoy
Rank: 8Rank: 8
来 自:mcu
等 级:蝙蝠侠
威 望:8
帖 子:436
专家分:832
注 册:2016-9-17
  得分:0 
强迫症患者的版本
#include<stdio.h>
 void main()
 {
     int year,month;
     printf("input year and month:");
     scanf("%d%d",&year,&month);
      switch(month)
          {
              case 1:printf("the days of %d of %d is 31",year,month);break;
              case 2:
                     if((year%4==0&&year%100!=0)||(year%400==0))
                      printf("the days of %d of %d is 29",year,month);
                      else printf("the days of %d of %d is 28",year,month);
                        break;
              case 3 :printf("the days of %d of %d is 31",year,month);break;
              case 4 :printf("the days of %d of %d is 30",year,month);break;
              case 5 :printf("the days of %d of %d is 31",year,month);break;
              case 6 :printf("the days of %d of %d is 30",year,month);break;
              case 7 :printf("the days of %d of %d is 31",year,month);break;
              case 8 :printf("the days of %d of %d is 31",year,month);break;
              case 9 :printf("the days of %d of %d is 30",year,month);break;
              case 10:printf("the days of %d of %d is 31",year,month);break;
              case 11:printf("the days of %d of %d is 30",year,month);break;
              case 12:printf("the days of %d of %d is 31",year,month);break;      
              default:printf("error input!\n");
      }
    }
 }

[此贴子已经被作者于2018-4-17 09:29编辑过]


电闪雷鸣之际 ,当心无杂念,安心渡劫
                                         -18.06.21
2018-04-17 09:26







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

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