Thread: Ahhh functions!!! helpz

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    Ahhh functions!!! helpz

    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    #include <ctype.h>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char choice;
        printf("\n");
        Sleep(100);    
        printf("\n");  
        Sleep(100);
        printf("\n");   
        Sleep(100);
        printf("\t\t\t       By Me\n");
        Sleep(100);
        printf("\n");
        Sleep(100);    
        putchar('\n');   
        Sleep(100);
        printf("\t\t\t        [N]ew Game\n");
        printf("\t\t\t        [Q]uit\n");
        Sleep(100);
        printf("\n");
        Sleep(100);
        printf("\n");
        choice=toupper(getch());
        for(;;)
        {
           if(choice=='N')
           {
               game();
               break;       
           }
           if(choice=='Q')
           {
              break;
           }    
        }
        return 0;
    }
    For some reason it keeps telling me that game is undeclared this is a dev project file btw,
    I named the file game and the function in the file is called game i added the file to the project i dont under stand why it is not working

  2. #2
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    game(); looks like a call to a function to the compiler. You do not have a function named game declared in that code. If you are trying to link it in from another file you have to include it like you did so many other things at the top. There is also room to improve your printf and sleeps.
    Search cout for some ideas. If you feel you 'must' have all of those sleeps, blank lines etc, remember this:
    Any time you type the same thing over and over in your code, there is probably a shorter way.
    Asking a question you already know the answer to might teach you something you did not know...

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    44
    Where's "game()" declaration?...that should be the problem...and why u use for(; for that?...just use and if, else sentence.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I see my example didn't do you any good.

    Oh, well...

    Soma

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    As ive said its a project file everything is their its just saying its undeclared and i tried using #include <game> but that isnt going to work concidering then id have to put game in the folder were headers go

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    if you have made your own header like:

    game.h

    Code:
    #ifndef GAME_H
    #define GAME_H
    
    game(); // whatever the return type and parameters are
    
    #endif
    You have to include it in main like so:

    Code:
    #include "game.h"
    Headers with < > are compiler pre-defined library files. Quoted names " " are programmer defined.
    Double Helix STL

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, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM