Enemy damaging with regen system Small project i made to practice my c++, im a beginner and want to know all about optimizing code.
Enemy starts off with 10 HP and we can damage them for 1 HP by pressing F1,
If their HP is below their max they regenerate 1 point each second.
#include &lt;time.h&gt;
#include &lt;Windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    int maxHP = 10;
    int enemyHp = maxHP;
    cout &lt;&lt; &quot;Enemy HP: &quot; &lt;&lt; enemyHp &lt;&lt; '\n';
    while (enemyHp &gt; 0)
    {
        if (GetAsyncKeyState(VK_F1) &amp; 1)
        {
            enemyHp--;
            system(&quot;CLS&quot;);
            cout &lt;&lt; enemyHp &lt;&lt; '\n';
        }
        static int sec = time(NULL);
        int secNew = time(NULL);
        int* secPtr = &amp;sec;

        if (sec != secNew)
        {
            if (enemyHp &lt; maxHP)
            {
                enemyHp++;
                system(&quot;CLS&quot;);
                cout &lt;&lt; enemyHp &lt;&lt; '\n';
            }
            *secPtr = secNew;
        }

        if (enemyHp == 0)
        {
            system(&quot;CLS&quot;);
            cout &lt;&lt; &quot;Enemy has died.\n&quot;;
        }
    }
    return 0;
}
```
Don't write using namespace std;.
maxHP should be constexpr or at least const.  In general, use const where you can.