undefined reference to function names
Ok I've already spent hours agonising of why my program didn't work and it turned out Switch should have been switch, but the error message "should have ; before {" was not very helpful.
Anyway now I am stuck again, I've made so many errors on this program that have been obvious, only it took me hours to figure out, but I think if this problem is figured out it hopefully will work.
Error message is:
Quote:
/tmp/cc4nHzG5.o: In function `main':
test.c:(.text+0x106): undefined reference to `qadd'
test.c:(.text+0x118): undefined reference to `qadd'
test.c:(.text+0x150): undefined reference to `qcheck'
The error applies to the other math functions to, I had to cut the quote short because it printed the smiley faces and there is a smiley face limit.
My program is not finished yet, but still...
Code:
#include <stdio.h>
#include <stdlib.h>
int qadd(int a, int b);
int qsubtract (int a, int b);
int qmultiply (int a, int b);
int qdivide (int a, int b);
int qcheck (int holdans);
main()
{
int score = 0;
int rs; /* Random math operator */
int ran1; /* Random number 1 */
int ran2; /* Random number 2 */
int holdans; /* Get answer from function and insert in another function to check if user guesses correctly */
int i;
for (i=0; i<=9; ++i) /* Ask 10 questions */
{
rs = rand() % 4 + 1; /* Random math operator (+,-,*, /) */
ran1 = rand() % 10 + 1; /* Random number between 1 and 10 */
ran2 = rand() % 10 + 1;
switch (rs)
{
case 1:
qadd(ran1, ran2);
holdans = qadd(ran1,ran2);
printf("\n \n: %d %c %d %c",ran1,'+',ran2,'=');
qcheck (holdans);
break;
case 2:
qsubtract(ran1, ran2);
holdans = qsubtract(ran1,ran2);
printf("\n \n: %d %c %d %c",ran1,'-',ran2,'=');
qcheck(holdans);
break;
case 3:
qmultiply(ran1, ran2);
holdans = qmultiply(ran1,ran2);
printf("\n \n: %d %c %d %c",ran1,'*',ran2,'=');
qcheck (holdans);
break;
case 4:
qdivide(ran1, ran2);
holdans = qdivide(ran1,ran2);
printf("\n \n: %d %c %d %c",ran1,'+',ran2,'=');
qcheck (holdans);
break;
}
}
int qcheck (holdans)
{
int guess;
scanf(" %d", &guess);
if (guess == holdans)
{
printf("Correct");
}
else
{
printf("Wrong");
}
}
int qadd (ran1, ran2)
{
int ans;
ans = ran1 + ran2;
return ans;
}
int qsubtract (ran1, ran2)
{
int ans;
ans = ran1 - ran2;
return ans;
}
int qmultiply (ran1, ran2)
{
int ans;
ans = ran1 * ran2;
return ans;
}
int qdivide (ran1, ran2)
{
int ans;
ans = ran1 / ran2;
return ans;
}
}
If it is obvious, please give a clue.