c - 时间表测验(错误)

标签 c if-statement syntax-error expression

需要帮助:D

所以尝试着手为我的时间表测验 brother.Very new to coding 所以尽量做到简单 可能但真的卡住了。任何帮助都是极好的 基本上我一直收到这个错误

[ 在函数“main”中:第 17 行:错误:“else”之前的预期表达式]

#include <stdio.h>

int main (){

int answers_eight[] = {8,16,24,32,40,48,56,64,72,80,88,96};
int answer ;

printf ("8x1 = : ");
scanf ("%d",&answer);

If (answer == '8');

{
    printf ("Correct");
}

else 
 {
    printf ("Incorrect");
}

return 0;
}

最佳答案

您的代码有各种语法错误(If 而不是 if,if 条件后的分号)。此外,您的代码在读取 int 然后与字符串进行比较时存在逻辑问题。此版本有效且缩进正确:

    #include <stdio.h>

int main (){

    int answers_eight[] = {8,16,24,32,40,48,56,64,72,80,88,96};
    int answer ;

    printf ("8x1 = : ");
    scanf ("%d",&answer);

    if (answer == 8) {
        printf ("Correct");
    } else {
        printf ("Incorrect");
    }

    return 0;
}

关于c - 时间表测验(错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867284/

相关文章:

c - 结构员工 {...} em1,em2;或 struct EMPLOYEE {...};

if-statement - Golang 模板变量 isset

python - 为什么 if 语句在 ElementTree 解析中不起作用?

javascript - 检查可变颜色

C编程: how to implement an insertion sort?

c - 执行一个将字符串从基数转换为 int 的函数

c - 如何在 C 中获取与寄存器宽度无关的无符号整数变量?

sql - INT或附近的PostgreSQL语法错误

javascript - "function x.y () {...}"出现语法错误?

php - mysql_error() 不显示错误