Thread: 2 quick questions on C!

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    21

    2 quick questions on C!

    Hi guys, I have 2 quick questions on C.

    If I have a function, thisfunction (), if i want to apply multiple numbers into it, like 37, 0, 100, etc. how would i go about doing that? I'm really stumped. So I want it to be like this:

    Code:
    //Prototype
    void printEvenOrOdd (int 37, int 0, int 3, int 777, int 10000);
    
    
    
    int main()
    {
    //Name:
        printf("YOO HOO\n");
        printf("Lab Exercise #10\n");
        printf("Code::Blocks\n");
        printf("\n");
    
    
    //Statements:
       printEvenOrOdd(37);
       printEvenOrOdd(0);
       printEvenOrOdd(3);
       printEvenOrOdd(777);
       printEvenOrOdd(10000);
       return 0;
    }
    
    
    
    void printEvenOrOdd(int 37, int 0, int 3, int 777, int 10000)
    {
        //Not Finished yet!
    }
    Am I using the prototype right? I'm stumped.

    My other question is one where I'm looking on printing the word even if its even, or odd if its odd. I'm not looking for any spoon fed answers, maybe a link to a page on how its done, or hints on it, but I've been looking in our textbook and no luck. My brain is frying over the frustration an easy problem is making. :/

    Thanks guys, you are awesome

  2. #2
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    Code:
     void printEvenOrOdd (int number);


    then you can use

    Code:
       printEvenOrOdd(37);
       printEvenOrOdd(0);
       printEvenOrOdd(3);
       printEvenOrOdd(777);
       printEvenOrOdd(10000);
    


    what your doing is basically saying

    i have a number, named number, and i send it to print if it is even or odd
    then after it prints you make number a new number, and send it again


  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    21
    Oh that's interesting. I didn't know you literally type the word number for all numbers to go through. I feel like a dummy. Hehe.

    It helps alot when you actually say it out. Thanks man <3

  4. #4
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Hmm. I think you misunderstand. 'number' has no special meaning, it is just the name of the variable that Crossfire chose as a descriptive parameter for the function. It could very well have been 'whatchamacallit'.
    It could even have just been
    Code:
    void printEvenOrOdd( int );
    because prototypes ignore parameter names - the compiler only cares about the datatype.

    Then
    Code:
    void printEvenOrOdd( int num )
    {
       //here num is a local  variable that is given the value you
       //passed to the function, i.e.
       //printEvenOrOdd( 17 );
    
       //you can manipulate num or use it in expressions
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with some quick questions.
    By jp5a9852 in forum C Programming
    Replies: 12
    Last Post: 11-10-2012, 07:43 PM
  2. 2 Quick questions
    By omGeeK in forum C Programming
    Replies: 2
    Last Post: 12-06-2010, 03:51 PM
  3. two quick questions
    By procyon4476 in forum Tech Board
    Replies: 6
    Last Post: 03-24-2003, 10:24 AM
  4. 2 quick questions
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 03-02-2002, 10:37 AM
  5. 2 quick questions
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-29-2001, 12:32 AM