a little problem in a basic "if" program

This is a discussion on a little problem in a basic "if" program within the C Programming forums, part of the General Programming Boards category; hello everyone, i have a little problem in a very basic program. this is the code Code: #include<stdio.h> main() { ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    Unhappy a little problem in a basic "if" program

    hello everyone,
    i have a little problem in a very basic program.
    this is the code
    Code:
    #include<stdio.h>
    main()
    {
          int n;
          printf("please could you enter an integer to verify it\n");
          scanf("%d",&n);
          if(n>=0);
          {
          printf("this is a positive integer\n");
          getchar();
          }
          if(n<0);
          {
          printf("this is a negative integer\n");
          getchar();
          }
    }
    by the way,
    what is the difference between " main()" and " int main()" and "int main(void)

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Quote Originally Posted by elton_fan
    i have a little problem in a very basic program.
    You forgot to say what the problem is.

    Quote Originally Posted by elton_fan
    what is the difference between " main()" and " int main()" and "int main(void)
    (1) and (2) are semantically the same, except (1) is stupider.
    (1) and (2) say main() takes a variable number of arguments, (3) says it takes none.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    What's the difference between... > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]) :
    http://faq.cprogramming.com/cgi-bin/...&id=1043284376

    And what is the problem?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    i thought that you were trying it in order to discover it.
    the problem is that whenever you write a number it shows the boths statments means " it's negative and positive too"

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Look at those ; at the end of your if statements - they mean "do nothing".
    The code in the braces happens anyway.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    oh thank you salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with my program i cant figure out...
    By youareafever in forum C Programming
    Replies: 7
    Last Post: 11-01-2008, 11:56 PM
  2. Replies: 4
    Last Post: 05-25-2008, 12:31 AM
  3. help with basic c program.
    By Uber Fr0g in forum C Programming
    Replies: 6
    Last Post: 09-26-2005, 06:59 PM
  4. Some Problem With My Program
    By Americano in forum C Programming
    Replies: 5
    Last Post: 10-18-2003, 01:58 AM

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