Simple pet caring game - console
Avoid using namespace std; - it can cause problems with name collisions. It's best to qualify names where necessary, e.g.: std::cout



std::endl adds a newline, but it also flushes the output stream. Unless we actually need the flushing behavior, it's best to simply output a newline &quot;\n&quot; where necessary (e.g. &lt;&lt; &quot;2. to clean your cat, type c\n&quot;).



char command; does not need to be a global variable. It's only accessed in a single function, so it can be a local variable.



The exit() function is not necessary. We can call std::exit(0) directly. Note that we should include &lt;cstdlib&gt; for this function, and use the exit codes EXIT_SUCCESS or EXIT_FAILURE instead of a number like 0.



Functions that are used only in a single file do not need to be declared in header files. If necessary, we can declare them above the point of use, or move the function definition higher up the file. e.g.:
void commandIdentify(); // forward declaration

int main() { ... }

void commandIdentify() { ... } // function definition

or
void commandIdentify() { ... } // function definition

int main() { ... }





In the Cat class, the happy and isClean members are not quite correct. They will only be set on initialization. If the cat's happiness or cleanness changes at a later time, they will not be updated. In addition, initialization of variables occurs before the body of the constructor, in the order that they are declared in the class.
For the initial values of happy and isClean to be set correctly, we would have to use a member initializer list:
Cat::Cat():
    happiness(1),
    /* `happy` is initialized here */
    cleanness(1),
    /* `isClean` is initialized here */
{
    // if we set happiness now, `happy` won't get updated!
    happiness = 0.2,
}

In any case, since we want the values to always be updated, we should make happy and isClean member functions instead:
bool isClean() const { return cleanness &gt;= 0.6; }

That way, we don't need to update any extra state.




Member functions that don't modify the state of the class (i.e. any member veriables) should be declared const, e.g.:
void checkHappiness() const { ... }





Cat cat; This doesn't need to be a global variable. We can make the cat a local variable in main() and pass a reference to it to the functions that need to use it:
int main() {
    Cat cat;
    ...
    commandIdentify(cat);
}

void commandIdentify(Cat&amp; cat) {
    ...
    feedCat(cat);
}

void feedCat(Cat&amp; cat) {
    ...
    cat.feed();
}

This may seem like more work, but it's quite important, as means that our commandIdentify function (and the functions for each command) will now work with any cat, not just the one cat that we declared in main().
So now we can feed many cats!