else语句导致在c 13中预期使用标识符

时间:2019-05-15 13:04:04

标签: c

我是C语言的初学者,还在学习语言

我无法确定错误的原因。

#include<stdio.h>
#include<math.h>
void main (void)
{
    float hours,rate;
    printf("Enter the number of hours worked in this week:\n");
    scanf("%f",&hours);
    printf("Enter the pay rate\n");
    scanf("%f",&rate);
    if ( hours > 40 );
        printf("more than 40");

    else{
        printf("less than 40");
    }
}

// c:13个标识符

2 个答案:

答案 0 :(得分:3)

问题是这里if ( hours > 40 );的分号放错了,只需删除分号即可。正确缩进代码以帮助检测此类错误是一种很好的做法。

答案 1 :(得分:0)

我想他想要这样的东西: 当然,如前所述,问题是if语句后的分号放错了位置。

#include<stdio.h>
#include<math.h>

void main (void)
{
    float hours,rate;
    printf("Enter the number of hours worked in this week:\n");
    scanf("%f",&hours);
    printf("Enter the pay rate\n");
    scanf("%f",&rate);
    if (hours > 40)
    {
        printf("more than 40");
    }
    else
    {
        printf("less than 40");
    }
}