Help with Programming in C

Amphituber

King Bowser
So I'm trying to learn C and I got this little program out of a book.

#include <stdio.h>

main()
{
int iResponse = 0

printf("\nEnter a number from 1 to 10:\n");
scanf("%d", &iResponse);

if ( iResponse < 1 || iResponse > 10 );
printf("\nNope.\n");
else
printf("\nYour number is %d. \n", iResponse);
}

But every time I try to compile it, I get this:

ez.c: In function ‘main’:
ez.c:12: error: expected expression before ‘else’

Little help? I can't figure out what the problem is, I'm new to programming.
 
I only know very VERY basic C, but based on the error code, I think something is messed up before "else" so check the whole nNope. thing. Of course might be something like your spacing or ; or brackets or whatever since I think sometimes those can screw things up.
 
Remove the Semicolon ( ; ) at the line of the If Statement.
Also, add a Semicolon ( ; ) at the end of the Int line, it's strange it didn't catch it.

So, your Code should look like this:
Code:
//Fixed my MKGirlism
#include <stdio.h>

main() {
   int iResponse = 0; //Fix'd.

   printf("\nEnter a number from 1 to 10:\n");
   scanf("%d", &iResponse);

   if ( iResponse < 1 || iResponse > 10 ) //Fix'd
      printf("\nNope.\n");
   else
      printf("\nYour number is %d. \n",  iResponse);
}
 
One more tip:
When using an Int or a Float, you don't need to use " = 0", as they're 0 by default already.
So:
Code:
int iResponse = 0;
Is the same as:
Code:
int iResponse;
 
Back