在编程方面我完全没用,所以记住这一点!
我们必须编写一个代码来生成两个随机数,然后将这两个随机数传递给一个函数,该函数生成并返回总和。系统会提示学生回答问题,如果他们答错了,程序应该循环直到他们答对,如果他们答对了,程序应该循环并提出另一个问题。
当我编译时,我不断收到这些错误:
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/