Results 1 to 4 of 4
  1. #1
    helloworld is offline Member
    Join Date
    Sep 2008
    Posts
    11
    Rep Power
    0

    Default Problem with Else if

    Hi guys! The following is a code I did, with if and else if statements. But I kept getting errors , saying that I can't have 'else' without an 'if' .

    public void PirateExplore(Player p) {
    double randomEventType = Math.random() * 100;
    if (randomEventType =< 5.00 ) {
    ItemResourceEventGenerator(p);
    }

    else if (randomEventType =< 12.50 ) {
    Random rgen = new Random();
    int type = rgen.nextInt(2);
    if (type == 0) {
    GoodEventGenerator(p);
    } else {
    BadEventGenerator(p);
    }
    }

    else if (randomEventType =< 70.00 ) {
    NothingEventGenerator(p);
    }




    Help! thanks!!!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    This is wrong actually. Not a legal expression in Java.

    Java Code:
    if (randomEventType =< 5.00 ) {
    You cannot do the comparison like this. It must be <=

  3. #3
    helloworld is offline Member
    Join Date
    Sep 2008
    Posts
    11
    Rep Power
    0

    Default

    Alright thanks!!

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •