| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 392 人关注过本帖
标题:求解...if else 嵌套的问题!!
只看楼主 加入收藏
等你的解答
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-3-19
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:8 
求解...if else 嵌套的问题!!
#include<stdio.h>

int main(void)
{
         int years, m, day;
         scanf("%d %d\n", &years, &m);
         if(years%400 == 0 || (years%4 == 0 && years%400 !=0));
         {
                if(m == 2)    {
                               printf("day=29");
                              }
                else {
                              if(m ==4 || m == 6 || m==9 ||m==11);
                              {
                               printf("day=30");
                              }  
                else          {
                              printf("day=31");
                              }
                     }
         }
         else
         {
                if(m == 2)    {
                               printf("day=28");
                              }
                else {
                              if(m ==4||m==6||m==9||m ==11);
                              {                  
                               printf("day=30");
                              }  
                else          {
                              printf("day=31");
                              }
                     }

         }
         return 0;
}


报错说的是else 前面没有if;求各位大侠帮帮忙,题目是:
输入年份和月份判断这个月份的天数。
搜索更多相关主题的帖子: void include 
2012-03-19 22:39
胖子221
Rank: 2
等 级:论坛游民
帖 子:6
专家分:11
注 册:2012-3-19
收藏
得分:2 
1.if{}
elseif{}
else{}
2.if{}
else{}
而且,else是和离它最近的if对应的,lz你写的嵌套是这样
if{}
else{}
else{}
不报错才怪
2012-03-19 22:45
a646404908
Rank: 6Rank: 6
等 级:侠之大者
威 望:5
帖 子:189
专家分:492
注 册:2012-2-14
收藏
得分:2 
#include<stdio.h>

int main(void)
{
         int years, m, day;
         scanf("%d %d", &years, &m);
         if(years%400 == 0 || (years%4 == 0 && years%400 !=0))
         {
                if(m == 2)   
                {
                     printf("day=29");
                }
                else if(m ==4 || m == 6 || m==9 ||m==11)
                {
                           
                     printf("day=30");
                 }  
                else         
                {
                     printf("day=31");
                }
                     
         }
         else
         {
                if(m == 2)   
                {
                     printf("day=28");
                }
                else if(m ==4||m==6||m==9||m ==11)
                {
                          
                     printf("day=30");
                }  
                else         
                {
                     printf("day=31");
                }
                  

         }
         return 0;
}
if后面不用加分号!!

[ 本帖最后由 a646404908 于 2012-3-19 22:56 编辑 ]
2012-03-19 22:54
jianyuling00
Rank: 3Rank: 3
来 自:琼州学院
等 级:论坛游侠
帖 子:89
专家分:177
注 册:2012-3-17
收藏
得分:2 
很简单,你的IF语句后面多出了分号;

系统认为语句结束了
2012-03-20 00:52
zxd675816777
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:252
专家分:631
注 册:2012-2-3
收藏
得分:2 
同上

数学好难!
2012-03-20 01:01
随着时间流逝
Rank: 1
等 级:新手上路
帖 子:2
专家分:3
注 册:2011-3-25
收藏
得分:2 
多看看IF....ELSE.....用法
2012-03-20 01:38
等你的解答
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-3-19
收藏
得分:0 
多谢各位大侠!!!感激涕零!!!
2012-03-20 19:29
xielei0806
Rank: 2
等 级:论坛游民
帖 子:36
专家分:28
注 册:2012-3-20
收藏
得分:0 
#include<stdio.h>

int main(void)
{
         int years, m, day=0;
         scanf("%d %d\n", &years, &m);
         if(years%400 == 0 || (years%4 == 0 && years%400 !=0))
         {
                if(m == 2)    {
                               printf("day=29");
                              }
                else {
                              if(m ==4 || m == 6 || m==9 ||m==11)
                              {
                               printf("day=30");
                              }  
                else          {
                              printf("day=31");
                              }
                     }
         }
         else
         {
                if(m == 2)    {
                               printf("day=28");
                              }
                else {
                              if(m ==4||m==6||m==9||m ==11)
                              {                  
                               printf("day=30");
                              }  
                else          {
                              printf("day=31");
                              }
                     }

         }
         return 0;
}
if后面多了分号,并且最好初始化day=0这样就一点错误都没有

2012-03-20 21:14
喝醉的猫
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:68
专家分:120
注 册:2012-3-13
收藏
得分:0 
呵呵观摩一下,If语句不加分号的哦
2012-03-20 21:36
快速回复:求解...if else 嵌套的问题!!
数据加载中...
 
   



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

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