I'm completely useless when it comes to programming, so keep that in mind!
We had to write a code which generates two random numbers, and the two random numbers were then passed into a function which produced and then returned the sum. The student is prompted to answer the questions, if they get it wrong the program should loop until they get it right, and if they are correct the program should loop and ask another question.
When I compile I keep getting these errors:
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
Here is my code, can someone please help me:
#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;
}