NO

Author Topic: Number Guessing game  (Read 4095 times)

Thor102514

  • Guest
Number Guessing game
« 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.
« Last Edit: July 30, 2016, 06:23:24 PM by frankie »

Scripter

  • Guest
Re: Number Guessing game
« Reply #1 on: July 30, 2016, 01:08:26 AM »
Read the error messages... they are telling you what's wrong.


Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Number Guessing game
« Reply #2 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?  ::)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide