Thread: Calling Functions

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    4

    Calling Functions

    I'm trying to call a function that determine's if a number is odd or not. I know that if the number is divisible by 2, then it's even. I'm new to coding, and this is frustrating. I'm not even sure if I'm posting this in the right place, but any tips would be really helpful. Thank you.

    Code:
    #include <stdio.h>
    int isodd(intx);
    
    main()
    {int x;
     x=0;
     printf("Enter an Integer:");
     scanf("%d\n",&x);
     printf("The number is odd\n",isodd(intx);
     
    }
    
    int isodd(intx)
    { 
      int x;
      
      if(x%2==0)
       return 0;
       
      else
       return x;
       
    }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Moved to where it belongs. If a question is not specifically about Linux (or more generally, POSIX) features, it doesn't belong in the Linux programming forum.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If this is being done on Unix/Linux, then you should add "-Wall" to your gcc compile command, e.g. "gcc -Wall mycode.c" [you may have other options on there, which you should of course continue to use].

    Always understand and fix ALL the warnings.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    I can not find the C board for general programming questions. Can you tell me where the board is?

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    int isodd(intx);
    should be
    int isodd(int x);

    Code:
    else
       return x;
    better to make
    Code:
    else
       return 1;
    Code:
    printf("The number is odd\n",isodd(intx);
    looks all wrong
    maybe you want something like
    Code:
    printf("The number is &#37;s\n",isodd(x)?"odd":"even");
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    intx is not even a variable name... x is the variable name.
    And the indentation leaves a bit to be desired, as well.
    And main desires to return int, plus putting code on the starting bracket isn't so popular...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. Replies: 9
    Last Post: 01-26-2008, 03:12 AM
  3. calling functions: exit and return
    By 911help in forum C Programming
    Replies: 3
    Last Post: 12-28-2007, 01:24 PM
  4. I Need Help Defining and Calling Functions
    By jonbuckets in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2007, 09:46 AM
  5. Calling functions help
    By ForlornOdium in forum C++ Programming
    Replies: 14
    Last Post: 09-29-2003, 08:40 PM