Metalmine
Metalmine

Reputation: 81

Getting syntax error involving ';'

I am making a pokemon game and this section is giving me 3 errors: "Invalid expression term ';' (CS1525)" and "; expected(CS1002)"

public class HeldItem
{
    public static int CritCalc(bool item,bool skill, bool UsedItem,int dmg)
    {
        Random rand=new Random();
        Action jump=new Action();
        int i = rand()%100;
        double CritPerc = 6.25;
        if(item==true)
            CritPerc=12.5;
        else if(skill==true)
            CritPerc=12.5;
        else if(UsedItem==true)
            CritPerc=12.5;
        else if((item==true & skill== true) || (item==true & UsedItem == true) || (skill==true & UsedItem==true))
                CritPerc=25%;
        else if(item==true & skill == true & UsedItem==true)
            CritPerc=33.3%;
        if(Action) //jump
            CritPerc = 50%;
        if(i<CritPerc)
            dmg=2*dmg;
        else if(i>CritPerc)
            dmg==dmg;
        return dmg; 
    }
}

}

Maybe it is a silly problem but I don't know what it is

Upvotes: 2

Views: 112

Answers (4)

Tony
Tony

Reputation: 821

You have dmg ==dmg which is the wrong operator and if dmg already has the correct value just return it, dmg=dmg goes without saying

Upvotes: 1

Md Kamruzzaman Sarker
Md Kamruzzaman Sarker

Reputation: 2407

%(percent) operator in c# means modulo operation which takes two operand. but you give one. So it gives error.

Instead of

CritPerc=25%;

write

CritPerc=.25;

or

CritPerc=25/100;

and

dmg==dmg

causes error.

Upvotes: 2

helsont
helsont

Reputation: 4952

The line that says:

dmg == dmg;

Ah, the fatal '=' error.

Upvotes: 1

abelenky
abelenky

Reputation: 64710

You cannot specify percents in C#.

You have the following lines:

CritPerc=25%;
CritPerc=33.3%;
CritPerc = 50%;

That is invalid (Percent indicates the modulo operator in C#).

Instead, you probably want to specify the values as double floating point values.

CritPerc=0.25;
CritPerc=0.333;
CritPerc = 0.50;

Upvotes: 10

Related Questions