Results 1 to 5 of 5
  1. #1
    n00624657 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Trouble with "if-else" statements please help URGENT!

    alright so i have my code but for whatever reason i cant figure out why i keep getting the error "syntax error on token "else" , delete this token.

    i am creating a simple slot machine program with the "slots" being randomly generate number 1-10. so i need the program to check for 3 of a kind, two of a kind and none responding with the according system.out.println.
    again im assuming i am doing something wrong with my if else statements. so here is the code i have


    import java.util.Random;
    import java.util.Scanner;

    public class slotmachineapp {
    public static int bal = 10;
    public static void main (String[] args){

    Scanner scan = new Scanner (System.in);
    int win = 0, bet = 0;
    int slot1, slot2, slot3;
    int Winnings=0;
    Random generator = new Random();
    slot1 = generator.nextInt(10);
    slot2 = generator.nextInt(10);
    slot3 = generator.nextInt(10);


    bal = bal + win;

    System.out.println ("Your beginning balance is: " + bal);

    while (bet > 0 || win <= 0){
    {System.out.println ("To proceed, enter a bet or hit 0 to stop playing");
    bet = scan.nextInt();
    System.out.println ("Slot results: \n" + slot1 + slot2 + slot3);}

    if (slot1 == slot2 && slot1 == slot3);
    {win = ((Winnings + 99) * bet);
    System.out.println ("You have won: $" + win);
    System.out.println ("Balance: $" + (win + bal));}

    else
    if (slot1 ==slot2 && slot1 != slot3 || slot2 == slot3 && slot2 != slot1 || slot3==slot1 && slot3!=slot2)
    {win = (Winnings+bet);
    System.out.println ("You have won:" + win);
    System.out.println ("Balance: $" + (win + bal) );
    }

    else
    if (slot1 != slot2 && slot1!= slot3 && slot2 != slot3)
    {win= (bal-bet);
    System.out.println ("You have lost:" );
    System.out.println ("Balance: $" + ((bet - bal)));
    }







    }
    }}

    again please help me out! thanks everyone

  2. #2
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: Trouble with "if-else" statements please help URGENT!

    You have to delete the semicolon
    Java Code:
    if (slot1 == slot2 && slot1 == slot3);
    You must have always have {} in your else statement body

  3. #3
    n00624657 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: Trouble with "if-else" statements please help URGENT!

    I've seriously been staring at this for 4 hours trying to get it to work. thank you so much!!

  4. #4
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: Trouble with "if-else" statements please help URGENT!

    did we helped you? please hit the reputation.. ^_^

  5. #5
    n00624657 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: Trouble with "if-else" statements please help URGENT!

    of course!

Similar Threads

  1. I cant figure out my "if "else" statements any help?
    By prendergast36 in forum New To Java
    Replies: 9
    Last Post: 09-17-2011, 01:36 AM
  2. Replies: 3
    Last Post: 04-29-2011, 02:08 AM
  3. Replies: 8
    Last Post: 03-01-2011, 06:44 PM
  4. trouble with Scanner(new File("input"));
    By ronyosi in forum New To Java
    Replies: 9
    Last Post: 10-28-2010, 12:34 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

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