| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2459 人关注过本帖
标题:错误显示illegal else without matching if,求大神指点
只看楼主 加入收藏
shallwt
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2018-10-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
错误显示illegal else without matching if,求大神指点

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int main()
{
        char diet;
    char sports;
    char sex;
    char M;
    char F;
    char Y;
    char N;
    float faHeight;
    float moHeight;
    float myHeight;
    printf("please enter your Father's Height and your Mother's Height(cm)\n");
    scanf("%f%f",&faHeight,&moHeight);
    printf("if you are a boy,please enter'M',or enter'F'\n");
    scanf(" %c",&sex);
    if(sex==M);
    {
        myHeight=(faHeight+moHeight)*0.54;
        printf("if you love sports ,please enter Y,or enter N\n");
        scanf(" %c",&sports);
        if(sports==Y);
        {
            myHeight=myHeight*(1+0.02);
            printf("if you have healthy diet,please enter'Y',or enter'N'\n");
            scanf(" %c",&diet);
            if(diet==Y);
            {
                myHeight=myHeight*(1+0.02);
                printf("your future height:%f\n",myHeight);
            }
            else if (diet==N);
            {
                printf("your future height:%f\n",myHeight);
            }
        }
        else if(sports==N);
        {
            printf("if you have healthy diet,please enter'Y',or enter'N'\n");
            if(diet==Y);
            {
                myHeight=myHeight*(1+0.02);
                printf("your future height:%f\n",myHeight);
            }
            else(diet==N);
            {
                printf("your future height:%f\n",myHeight);
            }
        }
    }
    else(sex==F);
    {
        myHeight=(faHeight*0.923+moHeight)/2;
        if(sports==Y);
        {
            myHeight=myHeight*(1+0.02);
            printf("if you have healthy diet,please enter'Y',or enter'N'\n");
            scanf(" %c",diet);
            if(diet==Y);
            {
                myHeight=myHeight*(1+0.02);
                printf("your future height:%f\n",myHeight);
            }
            else(diet==N);
            {
                printf("your future height:%f\n",myHeight);
            }
        }
        else(sports==N);
        {
            printf("if you have healthy diet,please enter'Y',or enter'N'\n");
            if(diet==Y);
            {
                myHeight=myHeight*(1+0.02);
                printf("your future height:%f\n",myHeight);
            }
            else(diet==N);
            {
                printf("your future height:%f\n",myHeight);
            }
        }
    }
   
    return 0;  
}
2018-10-03 18:29
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10610
专家分:43210
注 册:2014-5-20
收藏
得分:10 
else if (diet==N);
else(diet==N);
等等
2018-10-03 18:39
shallwt
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2018-10-3
收藏
得分:0 
回复 2楼 吹水佬
那我应该怎么使用呢
2018-10-03 18:51
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1745
专家分:3216
注 册:2015-12-2
收藏
得分:10 
else后面不要加括号
2018-10-03 20:04
快速回复:错误显示illegal else without matching if,求大神指点
数据加载中...
 
   



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

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