Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting syntax error involving ';'

Tags:

c#

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

like image 255
Metalmine Avatar asked Jun 09 '26 06:06

Metalmine


1 Answers

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;
like image 158
abelenky Avatar answered Jun 11 '26 18:06

abelenky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!