When I try to compile this:

//Player Class Definitions
#include <iostream>
#include "player.h"
using namespace std;

player::player()
{
    health = 100;
    level = 1;
    potions = 10;
    enemiesDefeated = 0;            
}

int player::attack(int *enemyHealth)
{
     srand(time(NULL));
     int randomNumber = rand() % 100;
     *enemyHealth = *enemyHealth - randomNumber;
}
int player::heal(int *playerHealth)
{
    if (potions > 0)
    {
               srand(time(NULL));
               int randomNumber = rand() % 100;
               if (randomNumber <= 30)
               {
                  health = health + 10;
               }
               else if (randomNumber >= 31 && <= 59) 
               {
                  health = health + 20;
               }
               else if (randomNumber >= 60 && <= 80) 
               {
                  health = health + 30;
               }
               else 
               {
                    return 0;
               }
    }
    
}

in Dev-C++, i get the error: "expected primary-expression before '<=' token". What does this mean? How can I fix it?

Thanks in advance,
EpicAsian

Recommended Answers

All 2 Replies

else if (randomNumber >= 31 && <= 59) is not valid syntax it must be else if (randomNumber >= 31 && randomNumber<= 59) . The same thing for line 34.

As an aside, you only need to call srand one time in your program.

else if (randomNumber >= 31 && <= 59) is not valid syntax it must be else if (randomNumber >= 31 && randomNumber<= 59) . The same thing for line 34.

As an aside, you only need to call srand one time in your program.

thank you for that...I knew it must have been something obvious,

Thanks Again,
EpicAsian

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.