Thread: Noob Question about classes

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    12

    Noob Question about classes

    Hello -

    I have been going through the C++ tutorial about classes. I decided to try a simple program to practice. The program asks the users for a cook time and says if the cooking worked or not depending on if the time entered is positive. I am getting an error that I can't figure out when I try to compile. The error says: expected unqualified-id before '.' token. It occurs on the line:

    Code:
    cook_successful = microwave.cook_food(cook_time);
    Here is the program:

    Code:
    #include <iostream>
    
    using namespace std;
    
    typedef enum
    {
        FALSE = 0,
        TRUE
    } bool_e;
    
    class microwave
    {
    public:
        microwave();
        ~microwave();
        bool_e cook_food (int cook_time);
    protected:
        int cook_time;
    };
    
    microwave::microwave()
    {
        cook_time = 0;
    }
    
    microwave::~microwave()
    {
    
    }
    
    bool_e microwave::cook_food (int cook_time)
    {
        if (cook_time <= 0)
        {
            return FALSE;
        }
    
        else
        {
            return TRUE;
        }
    }
    
    int main()
    {
        int cook_time;
        bool_e cook_successful;
        cout << "Enter desired cook time: ";
        cin >> cook_time;
        cin.ignore();
        cook_successful = FALSE;
    
        while (!cook_successful)
        {
    
            cook_successful = microwave.cook_food(cook_time);
    
            if (cook_successful)
            {
                cout<< "Enjoy your food!";
            }
    
            else
            {
                cout<< "Cook time must be a positive number. \n Re-enter desired cook time: ";
                cin >> cook_time;
                cin.ignore();
            }
        }
        cin.get();
    }
    Thanks in advance!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You need to create an actual instance of a microwave object and call the member functions for that object... either that or make your member functions static and then you don't need an instance.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    12
    Of course. I thought it was probably something easy. Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob question about RAM
    By crvenkapa in forum Tech Board
    Replies: 2
    Last Post: 03-26-2010, 03:41 PM
  2. Noob question about GDI again.
    By abachler in forum Windows Programming
    Replies: 5
    Last Post: 03-22-2009, 12:03 PM
  3. Noob question about classes
    By Dondrei in forum C++ Programming
    Replies: 12
    Last Post: 06-28-2008, 03:56 PM
  4. Another Noob Question
    By Nightwarrior in forum C++ Programming
    Replies: 10
    Last Post: 10-13-2007, 01:03 PM
  5. (noob) Question about classes
    By abachler in forum Windows Programming
    Replies: 6
    Last Post: 09-22-2007, 04:27 AM