Undefined Function...

This is a discussion on Undefined Function... within the C++ Programming forums, part of the General Programming Boards category; Ok here is the code for the very beginning of my program. Code: #include <iostream> #include <fstream> #include <string> #include ...

  1. #1
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60

    Undefined Function...

    Ok here is the code for the very beginning of my program.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdlib>
    #include <windows.h>
    
    using namespace std;
    
    void create(); 
    // This makes the create function, which allows me to use the creatdata funtion.
    void createdata(string rac); 
    // Creates character data, after character is created.
    void menu();
    // Allows game menu to show up.
    void story();
    // Begins story.
    void adventure1();
    // Starts you on your travels.
    void cleft();
    // Chose to go left in adventure1
    void cright();
    // Chose to go right in adventure1.
    void cdry();
    // You entered the cave in RIGHT.
    void cwet();
    Ive used all those functions so far. It says that create(), creatdata(string rac), menu(), and story() all work. Yet, it says that adventure1(), cleft(), cright(), cdry(), and cwet() are undefined. I cant seem to figure out why. That right there shows them being defined doesnt it?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Well... those are prototypes... did you define them at the end of your program?
    Code:
    void foo(); // This is a function prototype
    
    int main() {
       foo(); // This is a function call
    
       return 0;
    }
    
    void foo() {
       cout << "This is a function definition.";
    }
    If you did define them, then let me see your funtion calls as you might not be calling them properly.
    Sent from my iPadŽ

  3. #3
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Well here is how I used them:

    Code:
    //iostream, with voids and whatnot.
    
    int main()  {
    //.................
    
    void create() {
    // In here I used an if statement so say:
    
             if (yn == "y" || yn == "Y")
               {
                cout << "Data Created.\n"
                createdata();
                menu;
               }
         }
    void menu(){
    // Bascially the same as create() but with different questions, and stuff.
    }
    // Rest of program uses adventure1(), cright(), cleft(), cdry(), and cwet() basically the same way.
    If that wasnt a good discription, let me know.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Are you implying that you're defining the function inside of main? That's not legal. Also the function call to menu is incorrect in your create function. Please paste you actual code rather than writing some quick rewrite that has more errors in it than your actual code.
    Sent from my iPadŽ

  5. #5
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Here is a direct copy of my program including the voids at the top and part of void create() inside of main.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdlib>
    #include <windows.h>
    
    using namespace std;
    
    void create(); 
    // This makes the create function, which allows me to use the creatdata funtion.
    void createdata(string rac); 
    // Creates character data, after character is created.
    void menu();
    // Allows game menu to show up.
    void story();
    // Begins story.
    void adventure1();
    // Starts you on your travels.
    void cleft();
    // Chose to go left in adventure1
    void cright();
    // Chose to go right in adventure1.
    void cdry();
    // You entered the cave in RIGHT.
    void cwet();
    // You walk in the rain in RIGHT.
    void adventure2();
    // Sixth part of adventure.
    void adventure3();
    // Seventh part of adventure.
    void adventure4();
    // Eight part of adventure.
    void adventure5();
    // Ninth part of adventure.
    void adventure6();
    // Final adventure.
    void ending();
    // Final text display in game, before credits.
    void credits();
    // Credits appear on screen.
    
    
    
    int main(){
        string select;
        
        SetConsoleTitle("Rise of Darkness v1.0");
        
        HANDLE hOut;
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        
        do 
        {
             cout << "Welcome to the great world of Darkonia!\n";
             cout << "Please select an option below to start your quest.\n\n";
             cout << "Create Character [press C]\n";
             cout << "Game Info [press I]\n";
             cout << "EXIT [press X]\n";
             cin >> select;
             cout << endl;
             
             if (select == "c" || select == "C")
             {
                        create();
             }
             else if ( select == "i" || select == "I")
             {
                  cout << "You play as the young Riako. You average eveyrday\n";
                  cout << "medieval knight. Your set on the task of finding\n";
                  cout << "the great Scroll. Do you have what it takes to survive\n";
                  cout << "the journey, slay the beasts, grab the scroll and make it back?\n";
                  cout << "If you think so, create your character type and being.\n\n\n";
                  
                  cout << "No matter what race you make, it is a male and his name is\n";
                  cout << "Riako. Creating the character was just a little practice with code.\n\n\n";
    
             }
             else if (select == "x" || select == "X")
             {
                  break;
             }    
             else 
             {
                  SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED |
                                FOREGROUND_INTENSITY);
                  cout << "Sorry, that is not a proper selection. Please choose again.\n\n\n\n" << endl;
                  SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED |
                                FOREGROUND_GREEN |
                                FOREGROUND_BLUE);
             }
         }while (select != "x" || select != "X");
    }
    void create() {
    
         string rac; // Used to choose a race
         string yn; // Used to choose whether or not to use the chosen race.
    
                   cout << "Welcome to Character Creation.\n";
                   cout << "Select a character race.\n\n";
                   cout << "Human (press H)\n";
                   cout << "Elf (press E)\n";
                   cout << "Werewolf (press W)\n";
                   cout << "Dwarf (press D)\n";
                   cin >> rac;
                   cout << endl;
                   
                   if (rac == "h" || rac == "H")
                   {
                              cout << "Humans specialize in stubborness.\n";
                              cout << "Since the humans are so stubborn they are able to\n";
                              cout << "fight hard and long. Although, humans have soft skin\n";
                              cout << "and fragile bodies, this makes them supceptable\n";
                              cout << "to lots of damage. To protect a human, money is required\n";
                              cout << "to buy armor and weapons.\n\n\n";
                              cout << "Are you sure you want to be a human? Y/N:";
                              cin >> yn;
                              if (yn == "Y"|| yn == "y")
                              {
                                      cout << endl << "Data created.\n\n\n";
                                      createdata(rac);
                                      menu();
                                      }
                               else
                               {
                                    create();
                                    }
                                cin.get();
                         }
    It said that the create() was fine. Thats why I dont really get why the other couple of functions dont work.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Where are the other functions? Are you imagining that you defined them?
    Sent from my iPadŽ

  7. #7
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    No, that was just a chunk out of it.

    In it, shows how I used create(), and it worked fine. Like here:

    Code:
    if (select == "c" || select == "C")
             {
                        create();
             }
    Also here where I used menu(), and createdata()..which both work fine.

    Code:
    if (yn == "Y"|| yn == "y")
                              {
                                      cout << endl << "Data created.\n\n\n";
                                      createdata(rac);
                                      menu();
                                      }
    Also, dude if your making fun of me or something...I dont appreciate that as ive only been programming since like last Thursday night. My friend taught me most of what I know, and a few things I just looked at briefly. Im trying to make a short text based game, with what i know. I know enough to make it, I just need some help with this part and my firned isnt availbe right now. He might not be for a while as well.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    I'm not making fun of you, but you're asking a question about why some piece of code isn't working, yet the only code you've shown me so far is that part that is working. So where's the logic in that? You can't show me working code and then say "...and by the way the part that doesn't work is the same" and expect me to believe that it exists and doesn't work.
    Sent from my iPadŽ

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,826
    You need to post a COMPLETE program which is shorter than what you have at present, and which still demonstrates the problem.

    Simply copy/pasting random bits of the code you have just isn't going to work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Well im not sure what to show you. It just says linker error so im not really sure where I didnt use the functions correctly. Here is the adventure1(), when the player presses R it will bring up cright() and when they press L it should bring up cleft().

    Code:
    void adventure1();
    {
         string rl;
         
         
         cout << "You begin your travels alone. All you have with you is a small amount\n";
         cout << "of bread, and a few containers of water. After walking for several\n";
         cout << "hours, you come to a fork in the road. There lay two pathes ahead.\n\n";
         cout << "The path to the left looks very pleseant and happy.\n";
         cout << "The path to your right seems very grimy, and dead.\n\n";
         
         
         cout << "Which direction do you choose? Right(press R) or Left(press L)?\n\n";
         if (rl == "R" || rl == "r")
         {
                cout << "You have chosen to take the path to your right. You\n";
                cout << "turn right and start walking again.\n";
                cright();
                }
         else (rl == "L" || rl == "l");
         {
              cout << "You have chosen to take the path to your left. You\n";
              cout << "turn left and start walking again.\n";
              cleft();
              }
              }
    Like I said, I dont really no where I used it wrong. So if this doesnt help...I dont know what else I can show you.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,826
    > void adventure1();
    Get rid of that ;

    > else (rl == "L" || rl == "l");
    Else doesn't have a condition, and it doesn't have a ; either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM

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