Newbie Help!

This is a discussion on Newbie Help! within the C Programming forums, part of the General Programming Boards category; I'm getting an error where it says 'num' undeclared (first use in this function). I haven't used 'num' at all ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    51

    Newbie Help!

    I'm getting an error where it says 'num' undeclared (first use in this function). I haven't used 'num' at all in the code.

    Code:
    Code:
    /* The following program checks if a number is even or odd */
    
    #include <stdio.h>
    #include "genlib.h"
    #include "simpio.h"
    
    main()
    {
          int num1, num2;
          printf ("Enter an integer ");
          num1 = GetInteger();
          num2 = num1;
          if (num1 < 0);
          num1 = -num1;
          else;
          num1 = num1;
          if (num2%2==0);
          printf ("The number %d is even and its absolute value is %d.", num2, num1);
          else
          printf ("The number %d is odd and its absolute value is %d.", num2, num1);
          getchar();
          }
    Errors:
    Code:
     C:\Dev-Cpp\exercises\positive.c In function `main':
    15 C:\Dev-Cpp\exercises\positive.c syntax error before "else" 
    17 C:\Dev-Cpp\exercises\positive.c `num' undeclared (first use in this function)
      (Each undeclared identifier is reported only once 
      for each function it appears in.) 
    19 C:\Dev-Cpp\exercises\positive.c syntax error before "else"
    Last edited by PYROMANIAC702; 07-11-2011 at 04:20 AM.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58
    6 lines from the bottom you use "if (num%2==0)

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    51
    i fixed that, but the error is before that.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58
    you are closing your else statement with ; ..... you don't want to do that. Also, if statements don't get ; on their line either.
    Last edited by time4f5; 07-11-2011 at 04:16 AM.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    51
    Quote Originally Posted by time4f5 View Post
    you are closing your else statement with ; ..... you don't want to do that. Also, if statements don't get ; on their line either.
    Thanks! It's my first time working with if/else statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  2. SDL + Newbie
    By Livijn in forum Game Programming
    Replies: 7
    Last Post: 04-30-2007, 11:20 PM
  3. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 11:27 AM
  4. Newbie needs help
    By Getintothegame in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2003, 02:07 AM
  5. Some help for a newbie!!!
    By zehm in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 10:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21