c - 编译C程序时一直报错:(

标签 c

在编程方面我完全没用,所以记住这一点!

我们必须编写一个代码来生成两个随机数,然后将这两个随机数传递给一个函数,该函数生成并返回总和。系统会提示学生回答问题,如果他们答错了,程序应该循环直到他们答对,如果他们答对了,程序应该循环并提出另一个问题。

当我编译时,我不断收到这些错误:

multi.c: In function ‘multiply’:
multi.c:6:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
multi.c:27:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
multi.c:31:1: error: expected ‘{’ at end of input

这是我的代码,有人可以帮助我吗:

#include <stdio.h>

int multiply(int x, int y)

int main()
{
    int multiply(int x, int y);
    int x = rand()%20;
    int y = rand()%20;
    int i, answer;
    i = multiply(x,y);

    printf("what is %d multiplied by %d\n?" x, y);
    scanf("%d\n", &answer);

    while(answer != i)
    {
        printf("wrong try again!");
        scanf("%d\n", &answer);
    }

    printf("very good!");
}

int multiply(int x, int y)
{
    int k;
    (x*y = k);
    return k;
}

最佳答案

第 27 行 x*y = k 的赋值应该是 k = x*y

第 6 行 int multiply(int x, int y) 后少了一个分号。

第 13 行的字符串字面量后缺少一个逗号:

printf("what is %d multiplied by %d\n?" /* here */ x, y);

关于c - 编译C程序时一直报错:(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9952822/

相关文章:

使用信号处理程序的正确方法

c - 如何通过执行 exec 终止正在运行另一个程序的子进程

C - 无法释放链表结构中分配的内存

c - 为什么采用 sizeof(array) 会在函数中发出警告,但在 main() 中却不会?

c - ALSA中period的含义

c - 是否有 strncmp() 的惯用用法?

c - C 中的指针,使用数组获得意外结果

c - c中的windows异步串口通信

c - strtok - 向前移动一位

c - 无法退出 while 循环