954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

expected primary-expression before '<=' token ?

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

epicasian
Junior Poster in Training
53 posts since Nov 2009
Reputation Points: 12
Solved Threads: 0
 

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.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

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

epicasian
Junior Poster in Training
53 posts since Nov 2009
Reputation Points: 12
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You