Thread: functions? what? how?huh?

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    7

    functions? what? how?huh?

    can someone please tell me how and where to add prototypes for the functions in this program. I've only started a couple of days ago, and im really confused.
    #include <iostream.h>
    #include <conio.h>
    int main()
    {
    int input;
    cout<<"1. Play game";
    cout<<"2. Load game";
    cout<<"3. Play multiplayer";
    cout<<"4. Exit";
    cin>>input;
    switch (input)
    {
    case 1: playgame();
    break;
    case 2:
    loadgame();
    break;
    case 3: //Note use of : not ;
    playmultiplayer();
    break;
    case 4:
    return 0;
    default:
    cout<<"Error, bad input, quitting";
    }
    return 0;
    }

    I got this from the tuts on this site. Thanks for time, and have a nice day.

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    I dont normally read code without tags but I'm feeling helpful cos its Friday...

    Code:
    #include <iostream>
    
    int function1( );  //prototype
    
    int main( )
    {
       //code here
       .
       .
       .
       .
       .
       .
    }
    
    int function1( )    //function definition
    {
       //code here
    }

    If you put the function definition above main( ), you do not need prototypes. You can also put prototypes and defintions in diffenret files but dont worry about that until you're confident using functions in a single file
    Couldn't think of anything interesting, cool or funny - sorry.

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    You put function prototypes just before the main() function, but the program you wrote above has only the main() function, and you don't a prototype for the main() function.
    none...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  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