Functions are killing me

This is a discussion on Functions are killing me within the C++ Programming forums, part of the General Programming Boards category; Hi can someone please look at this and tell how i can use a switch statement called print to work ...

  1. #1
    Registered User mike's Avatar
    Join Date
    Aug 2001
    Posts
    12

    Functions are killing me

    Hi can someone please look at this and tell how i can use a switch statement called print to work with my program. I think my problem is in the functions. all the functions work as the program is now but when i make a function called print and use a switch statement then i have problems. im still trying to learn to pass by value and its messing me up. hope you can help thanks!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    3
    Hello Mike,
    I hope that the text file I downloaded is corrupt, and not identical to your source code. This can't be working, The <do> loop and the <switch> statement in the main function is not matched. The showMenu function does not return anything. Please check out the code and try again.
    But just a guess: can it just be that the name <print> is already taken?

  3. #3
    Sayeh
    Guest
    Pointers seem to be the biggest thing everyone has problems with-- think of it this way--

    Passing by Value= contents of variable
    Passing by Reference = address of variable

    Code:
    void foo1(char);                           /* prototypes */
    void foo2(char*);
    int main(void);
    
    
    int main(void)
       {
       char  myLetter;
    
       myLetter = 'X';
    
       foo1(myLetter);                        /* pass by value (contents of 'myLetter') */
       foo2(&myLetter);                      /* pass by reference (refer to contents by passing address of 'myLetter') */
    
       return(0);
       }
    
    
    void foo1(char letter)
       {
       if(letter == 'X')                           /* look at value of 'letter' */
          Beep();
       }
    
    
    void foo2(char *letter)
       {
       if(*letter == 'X')                        /* go through 'letter' which is address of original variable to get to contents */
          Beep();
       }

    enjoy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  3. functions are killing me
    By 77walker in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2004, 02:49 PM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM

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