CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2009
    Posts
    41

    why aren't my functions working?

    my program tht i am building for a class is based all most entirely on functions... and none of them are reading. i therefore have 7 errors from my functions not reading in main program. why?

  2. #2
    Join Date
    Aug 2009
    Posts
    20

    Re: why aren't my functions working?

    Some info, code, anything?

  3. #3
    Join Date
    Aug 2009
    Posts
    41

    Re: why aren't my functions working?

    here.

    #include <iostream>
    #include <string>
    #include <windows.h>
    using namespace std;
    int main ()
    {
    string s;
    string type;
    cout << "Enter first name and hit enter.\n";
    cin >> s;
    Sleep (500);
    cout << "Hello. " << s << ". I am the Game Master. Would you like to play a game? Yes or no?\n";
    getline(cin, type);
    if (type=="yes" || type=="ok" || type=="sure" || type=="yup" || type=="all right" || type=="okay" || type=="of course")
    cout << "Which one? I have several for you to choose from. There is a maze game, an adventure game, and a mini mystery game.\n";
    getline(cin, type);
    if (type=="the maze" || type=="maze" || type=="the maze game" || type=="maze game")
    maze();
    if (type=="the adventure" || type=="adventure" ||type=="the adventure game" || type=="adventure game")
    adventure();
    if (type=="the mini mystery" || type=="the mystery" || type=="the mini mystery game" || type=="the mystery game" || type=="mini mystery")
    mystery();
    if (type=="no" || type=="nope" || type=="nuh uh" || type=="nu uh" || type=="nada")
    cout << "Goodbye. See you later.\n";
    Sleep (500);
    system ("pause");
    system ("exit");
    else
    cout << "I don't like stupid answers.";
    Sleep(500);
    death();
    return 0;
    }
    void maze ()
    {
    string type;
    cout << "Welcome to the Labyrinth, the maze adventure game.\n There is a door in front of you. Do you open it?\n";
    cin.ignore();
    getline(cin,type);
    if (type=="yes" || type=="ok" || type=="sure" || type=="yup" || type=="all right" || type=="okay" || type=="of course")
    cout << "You open the door to find a dark room. What do you do? Be careful...\n";
    if (type=="creep in" || type=="tiptoe in" || type=="tip toe in" || type=="enter room carefully" || type=="go in carefully")
    cout << "You enter the dark room carefully and a large spear embeds itself into the ground at your feet. What do you do next?\n";
    system("pause");
    if (type=="walk in" || type=="walk into room" || type=="run in" || type=="run into room" || type=="enter room" || type=="charge in")
    cout << "You enter the dark room brashly... and get run through the head by a spear.\n";
    death();
    if (type=="no" || type=="nope" || type=="nuh uh" || type=="nu uh" || type=="nada")
    death();
    }
    void adventure ()
    {
    string type;
    }
    void mystery ()
    {
    string type;
    }

    void death ()
    {
    cout << "I'm sorry that you have died. \n";
    Sleep(2000);
    system("exit");
    }

    it's sloppy, yes, but it should work and it's definitely not finished.

  4. #4
    Join Date
    Dec 2007
    Posts
    76

    Re: why aren't my functions working?

    What errors are you getting.? And you may want to use "if else", instead of just "if" statements.

  5. #5
    Join Date
    Aug 2009
    Posts
    41

    Re: why aren't my functions working?

    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(18) : error C3861: 'maze': identifier not found
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(20) : error C3861: 'adventure': identifier not found
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(22) : error C3861: 'mystery': identifier not found
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(28) : error C2181: illegal else without matching if
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(31) : error C3861: 'death': identifier not found
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(47) : error C3861: 'death': identifier not found
    1>c:\users\owner\documents\visual studio 2008\projects\project 1- start!\project 1- start!\game romm 1.cpp(49) : error C3861: 'death': identifier not found
    1>Build log was saved at "file://c:\Users\Owner\Documents\Visual Studio 2008\Projects\project 1- start!\project 1- start!\Debug\BuildLog.htm"
    1>project code - 7 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    thats all of them. and whats the difference between an if and an if else? im realllllllllly new to this

  6. #6
    Join Date
    Oct 2006
    Posts
    14

    Re: why aren't my functions working?

    There is really no difference between the statements.. When using an else statement it immediately follows an if statement.. The else statement is executed if and only if the condition of the preceding if statement evaluates to zero...

  7. #7
    Join Date
    May 2008
    Posts
    38

    Re: why aren't my functions working?

    For all the 'identifier not found' errors you need to declare those functions before you use them. So after 'using namespace std;' add something like
    Code:
    void maze();
    void adventure();
    void mystery();
    void death();
    for all the functions you want to use........ For the other error about 'else', you need to change the following, bold bits have been added.....
    Code:
    if (type=="no" || type=="nope" || type=="nuh uh" || type=="nu uh" || type=="nada")
    {
            cout << "Goodbye. See you later.\n";
            Sleep (500);
            system ("pause");
            system ("exit");
    }
    else
    {
            cout << "I don't like stupid answers.";
            Sleep(500);
            death();
            return 0;
    }
    Last edited by Cheezewizz; August 10th, 2009 at 02:57 AM.

  8. #8
    Join Date
    Aug 2009
    Posts
    41

    Re: why aren't my functions working?

    gosh thanks i forgot that you had to declare your functions.

    i feel stupid about forgetting the brackets ni the if and else statements.

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured