what's wrong with this c++ code, help!!!

This is a discussion on what's wrong with this c++ code, help!!! within the C++ Programming forums, part of the General Programming Boards category; i'm making it for my cousin, idk whats wrong with it help!!! here it is: Code: /* Name: Critter Farm ...

  1. #1
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30

    what's wrong with this c++ code, help!!!

    i'm making it for my cousin, idk whats wrong with it help!!!

    here it is:

    Code:
    /*
      Name: Critter Farm
      Copyright: N\A
      Author: Trevor S. Lusk
      Date: 01/06/06 18:55
      Description: 
    */
    
    #include <iostream>
    
    using namespace std;
    
    class critter
    {
        public:
        critter(int hunger=0, int boredom=0);
        void talk();
        void eat(int food=4);
        void play(int fun=4);
        
        
        private:
        int m_Hunger;
        int m_Boredom;
        
        int getMood() const;
        void passTime(int time = 1);
    };
    
    critter::critter(int hunger, int boredom):
    m_Hunger(hunger),
    m_Boredom(boredom)
    {}
    
    inline int getMood() const
    {
        return (m_Hunger + m_Boredom);
    }
    
    
    void critter::passtime(int time)
    {
        m_Hunger += time;
        m_Boredom += time;
    }
    
    void critter::talk()
    {
        cout << "Cindy, I'm ";
        int mood=getMood();
        if (mood > 15)
            cout<<"mad. (you need to pay more attention to you're pet)";
        else if (mood > 10)
            cout<<"Frustrated.\n";
        else if (mood > 5)
            cout<<"okay, thanks for asking.\n";
        else
            cout<<"Happy, you're such a good owner!\n";
        passtime();
    }
    
    void critter::Eat (int food)
    {
    cout<<"Brruuupp! yumm! you're such a good cook! #1 :)\n";
    m_Hunger -= food;
    if (m_hunger<0)
        m_hunger=0;
    passtime();
    }
    void critter::play(int fun)
    {
        cout<<"weeeee! Cindy your so fun!";
        m_Boredom -= fun;
        if (m_Boredom < 0)
        m_Boredom = 0;
        passtime();
    }
    
    int main()
    {
        critter crit;
        crit.talk();
        
        int choice;
        do
        {
        
        cout << "\nDragon Caretaker\n\n";
        cout << "0-Quit\n";
        cout << "1-Listen to your baby dragon\n";
        cout << "2-Feed your baby dragon\n";
        cout << "3-play with your dragon\n\n";
        
        
        cout << "choice :";
        cin >> choice;
        
         switch (choice)
         {
         case 0;
              cout << "good bye, I'll miss you cindy! :(\n";
              break;
         case 1;
              crit.talk();
              break;
         case 2;
              crit.eat();
              cout << "Yumm! thanks cindy, your a good cook!\n";
              break;
         case 3;
              crit.play();
              break;
         default;
              cout << "ciny, I'm confused!?!\n";
         }
        }while (choice !=0);
        
        cout<<"hit enter to Exit";
        cin.ignore(cin.rdbuf()->in_avail()+1);
        return 0;
    }

  2. #2
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    bye the way the authors name has been changed...

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399

    A Clue

    Quote Originally Posted by lsctt
    i'm making it for my cousin, idk whats wrong with it help!!!
    First, give us a bit more to go on than just "something's wrong". An actual compiler error or run-time error would be a good start. Then, ask a specific question.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    here is the compiler log,

    Code:
    Compiler: Default compiler
    Executing  g++.exe...
    g++.exe "C:\Documents and Settings\Cindy\My Documents\trevors programs\grr.cpp" -o "C:\Documents and Settings\Cindy\My Documents\trevors programs\grr.exe"    -I"C:\c++\include\c++"  -I"C:\c++\include\c++\mingw32"  -I"C:\c++\include\c++\backward"  -I"C:\c++\include"   -L"C:\c++\lib"
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:36: non-
    
       member function `int getMood()' cannot have `const' method qualifier
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: In 
       function `int getMood()':
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:37: `
    
       m_Hunger' undeclared (first use this function)
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:37: (Each 
       undeclared identifier is reported only once for each function it appears 
       in.)
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:37: `
       m_Boredom' undeclared (first use this function)
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: At 
       global scope:
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:42: no `
       void critter::passtime(int)' member function declared in class `critter'
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: In 
       member function `void critter::talk()':
    
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:59: `
       passtime' undeclared (first use this function)
    
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: At 
       global scope:
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:63: no `
       void critter::Eat(int)' member function declared in class `critter'
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: In 
       member function `void critter::Eat(int)':
    
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:66: `
       m_hunger' undeclared (first use this function)
    
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp: In 
       function `int main()':
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:100: parse
       error before `;' token
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:103: parse
       error before `;' token
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:106: parse
       error before `;' token
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:110: parse
    
       error before `;' token
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:113: parse
       error before `;' token
    C:/Documents and Settings/Cindy/My Documents/trevors programs/grr.cpp:101: warning: unreachable
       code at beginning of switch statement
    
    Execution terminated
    its having isues with the { write before
    Code:
    return (m-Hunger + m_Boredom)

  5. #5
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    it's not telling me what kinda error it is...

  6. #6
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    basicly it just crashes there so probably a compier error

  7. #7
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    im new to c++ programing...

  8. #8
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    inline int getMood() const
    Isn't that a member function?

    Code:
    void critter::passtime(int time)
    void critter::passTime(int time)

  9. #9
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Code:
    inline int getMood() const
    You're missing a scope qualifier. Use:
    Code:
    inline int critter::getMood() const
    If you're new to C++, then you might want to take a look at the tutorials.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  10. #10
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    yea, i used inline to define getMood.

  11. #11
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    Code:
    inline int getMood() constYou're missing a scope qualifier. Use:
    Code:
    inline int critter::getMood() constIf you're new to C++, then you might want to take a look at the tutorials.
    thanks it worked

  12. #12
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    Did you seriously just register, drop a bunch of code down for others to fix, create a second thread to ask the same question, bump them both, then bump other people's threads in some futile attempt for attention?!?!?

    I haven't been here long, but is it possible someone's ever broken more board rules in such a short amount of time?

    it's not telling me what kinda error it is...
    basicly it just crashes there so probably a compier error
    It's a compiler error because the error occurs at compile-time. Guess when a run-time error occurs?
    bye the way the authors name has been changed...
    Oh, sure it has. That's why the file is stored in the "trevors programs" folder. Say hi to your mom Cindy for me.

    If you want getMood to be a member function, then make it one ( :: )
    There is a difference between tedious and difficult.

  13. #13
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    im using a book that's called begining c++ by micheal dalton, but theres no helo site in the back...

  14. #14
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by Decrypt
    Oh, sure it has. That's why the file is stored in the "trevors programs" folder. Say hi to your mom Cindy for me.
    Heh, noticed that, did you?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  15. #15
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    i made a new file called that so it couldn't be traced, after this trevor's files will be erased, im not stupid...

    my mom's name isn't cindy..

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 08:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 01:51 AM

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