Pelles C forum

C language => Beginner questions => Topic started by: Thor102514 on July 29, 2016, 10:48:33 PM

Title: Number Guessing game
Post by: Thor102514 on July 29, 2016, 10:48:33 PM
ok so i have been working on a class assignment for 2 weeks now and i cannot get it right for some reason. I have gone over this a million times and cant get  it can someone help. I have to use Pelles C, with simple codes, so bare with me.
Code: [Select]
#include <Stdio.h>
int main(int argc, char *argv[])
{
    int iRandomNum = 0;
    int iResponse = 0;
    srand(time(NULL));
    iRandomNum = (srand() % 10) + 1;
    printf("\nGuess a number between 1 and 10: "0;
    scanf("%d", &iResponse);
    if (iResponce == iRandomNum)
printf ("\nYou Guessed Right\n");
else {
printf("\nSorry that is incorrect\n");
printf("The correct number was %d\n", iRandomNum);
}
return 0;
}
this is my code

this is what i get as results
Code: [Select]
Building main.c number game.obj.
C:\Users\User\Documents\number guessing game\main.c number game.c(10): warning #2018: Undeclared function 'srand' (did you mean 'scanf'?); assuming 'extern' returning 'int'.
C:\Users\User\Documents\number guessing game\main.c number game.c(10): warning #2018: Undeclared function 'time' (did you mean '(no name)'?); assuming 'extern' returning 'int'.
C:\Users\User\Documents\number guessing game\main.c number game.c(14): error #2001: Syntax error: expected ')' but found 'integer constant'.
C:\Users\User\Documents\number guessing game\main.c number game.c(14): error #2001: Syntax error: expected ';' but found 'integer constant'.
C:\Users\User\Documents\number guessing game\main.c number game.c(18): error #2048: Undeclared identifier 'iResponce' (did you mean 'iResponse'?).
*** Error code: 1 ***
Done.
Title: Re: Number Guessing game
Post by: Scripter on July 30, 2016, 01:08:26 AM
Read the error messages... they are telling you what's wrong.

Title: Re: Number Guessing game
Post by: frankie on July 30, 2016, 06:26:23 PM
Just an hint: have you checked in which header srand and time functions are defined?
And do you actually include these headers?  ::)