Then try this
enum Elements { FIRE = 0, FROST, POISION, LIGHTNING, ELEMENTS_TOTAL};int randomAttack = rand() % ELEMENTS_TOTAL;
I added an extra enum value to Elements: ELEMENTS_TOTAL. Since FIRE is 0, the value of ELEMENTS_TOTAL will automatically be the number of elements in the enum (in this case 4). You can now use this constant to ensure you never get a random value more then the number of enum values in Elements. This also means that you can add more elements without changing other sections of code that rely on ELEMENTS_TOTAL. As long as it is at the end, the value will always be the number of values in the enum.
Personally, this is how I would have written it:
namespace Elements{enum EElements { FIRE = 0, FROST, POISION, LIGHTNING, TOTAL_NUMBER};}Elements::EElements randomAttack = static_cast<Elements::EElements>( rand() % Elements::TOTAL_NUMBER );
The namespace encapsulates all the enum values and randomAttack is the same type as the enum that it will be checked against for type safety.