10 Replies - 832 Views - Last Post: 12 October 2012 - 10:17 PM Rate Topic: -----

#1 bulletprooftiger  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 12-October 12

else if statement,else without if error

Posted 12 October 2012 - 12:19 PM

Hello,
I'm pretty new to programming and I've encountered what I'm sure is a pretty basic problem.
I am doing a survey of 20 people. A goal of the month competition. I have if else statement and I'm Having a problem with the last else statement.
Here is the code I'm struggling with
  {
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Fellani"+"Winner to be Announced Shortly",
// add 1 vote to Fellani
         JOptionPane.PLAIN_MESSAGE);Fellani++;}
//
         else
         {
        JOptionPane.showMessageDialog(null,"WRONG\n Seriously\n 1-5 ONLY","Invalid Entry!",JOptionPane.ERROR_MESSAGE);
         
      
         }
         


I hope I've posted this correctly.
Any advice greatly received.

Is This A Good Question/Topic? 0
  • +

Replies To: else if statement,else without if error

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: else if statement,else without if error

Posted 12 October 2012 - 12:31 PM

Very difficult to see where your error is from this small snippet.
Was This Post Helpful? 0
  • +
  • -

#3 bulletprooftiger  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 12-October 12

Re: else if statement,else without if error

Posted 12 October 2012 - 12:41 PM

Apologies here is the rest of the code
     // declaring variable players name as an integer assigning it  value 0
        int  Rooney = 0 ;
        int  Suarez = 0 ;
        int  Walcott = 0 ;
        int  Bent = 0 ;
        int  Fellani = 0 ;

// adding a loop
        for ( int i =0; i<20; i++)
        {
// start the loop,input data into dialoge box for 20 students, and give them choice of what goal to pick
         String vote =JOptionPane.showInputDialog(null,"Goal of the Month Competition October\n"+ "Vote Here :\n" +
        "1 for Goal 1: Rooney\n 2 for Goal 2: Suarez\n 3 for Goal 3: Walcott\n 4 for Goal 4: Bent\n 5 for Goal 5: Fellani");
// starting if statemnet
// checking to see if input data matches 1
         if(vote.matches("1"))
         {
//  output dialoge box confirms vote
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Rooney"+"Winner to be Announced Shortly",
// add 1 vote to Rooney
         JOptionPane.PLAIN_MESSAGE);Rooney++;
         }
//checking to see if inputdata matches
         else if(vote.matches("2"))
//output dialoge confirms vote
         {
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Suarez"+"Winner to be Announced Shortly",
// add 1 vote to Suarez
         JOptionPane.PLAIN_MESSAGE);Suarez++;
         }
//checking to see if input data matches
         else if(vote.matches("3"))
// output dialoge comfirms vote
         {
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Walcott"+"Winner to be Announced Shortly",
// add 1 vote to Walcott
         JOptionPane.PLAIN_MESSAGE);Walcott++;
         }
//checking to see if input data matches
         else if(vote.matches("4"))
//output dialoge confirms vote
         {
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Bent"+"Winner to be Announced Shortly",
// add 1 vote to Bent
         JOptionPane.PLAIN_MESSAGE);Bent++;}
//checking to see if input data matches
         else if(vote.matches("5")){
//output dialoge to confirm vote
         {
         JOptionPane.showMessageDialog(null,"Your Vote has been Register","You Have Voted for Fellani"+"Winner to be Announced Shortly",
// add 1 vote to Fellani
         JOptionPane.PLAIN_MESSAGE);Fellani++;}
//
         else
         {
        JOptionPane.showMessageDialog(null,"WRONG\n Seriously\n 1-5 ONLY","Invalid Entry!",JOptionPane.ERROR_MESSAGE);


         }


//if data doesn't match the input params





















        // TODO code application logic here




    





Was This Post Helpful? 0
  • +
  • -

#4 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: else if statement,else without if error

Posted 12 October 2012 - 01:15 PM

Honestly cannot see what is going on. Very hard to read code. No formatting what so ever.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8009
  • View blog
  • Posts: 13,716
  • Joined: 19-March 11

Re: else if statement,else without if error

Posted 12 October 2012 - 01:22 PM

Agree with Kinaces. The problem is likely a slipped close brace somewhere.
I suggest you take the time to go through this and manually format it. Use a consistent indentation, use Allman style braces so you can see them line up. This will almost certainly turn up the problem. If it doesn't, you'll be able to post the code again and it'll be less impossible to read it.
Was This Post Helpful? 1
  • +
  • -

#6 bulletprooftiger  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 12-October 12

Re: else if statement,else without if error

Posted 12 October 2012 - 01:29 PM

Thank you I'll go through it again and do as suggested.
Was This Post Helpful? 1
  • +
  • -

#7 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: else if statement,else without if error

Posted 12 October 2012 - 09:46 PM

I would suggest you use This link and it does the indentation automatically for you.:)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8009
  • View blog
  • Posts: 13,716
  • Joined: 19-March 11

Re: else if statement,else without if error

Posted 12 October 2012 - 09:50 PM

View Postraghav.naganathan, on 12 October 2012 - 11:46 PM, said:

I would suggest you use This link and it does the indentation automatically for you.:)

regards,
Raghav



Defeats the purpose, though. The point is precisely to perform a detailed review of the code, by hand. This is how you learn structure. :)
Was This Post Helpful? 0
  • +
  • -

#9 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: else if statement,else without if error

Posted 12 October 2012 - 10:01 PM

View Postjon.kiparsky, on 13 October 2012 - 10:20 AM, said:

View Postraghav.naganathan, on 12 October 2012 - 11:46 PM, said:

I would suggest you use This link and it does the indentation automatically for you.:)

regards,
Raghav



Defeats the purpose, though. The point is precisely to perform a detailed review of the code, by hand. This is how you learn structure. :)


What you say is probably right Jon. But at least this can be used as a last resort, don't you think? :)

regards,
Raghav

This post has been edited by raghav.naganathan: 12 October 2012 - 10:01 PM

Was This Post Helpful? 0
  • +
  • -

#10 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8009
  • View blog
  • Posts: 13,716
  • Joined: 19-March 11

Re: else if statement,else without if error

Posted 12 October 2012 - 10:04 PM

I can't tell anyone what to do or what not to do. I can tell you that when I suggest a thing be done manually, it's not meant as a punishment for some failure. There's a reason for it, and that reason is about helping you learn the craft.
But I might be wrong, and I'm not going to hold it against the original poster if they want to take short cuts. We're all adults here, and ultimately we're responsible for making these decisions for ourselves.
In this case, I believe there will be no need for last resorts - I have faith in bulletprooftiger's ability to re-format their code.
Was This Post Helpful? 1
  • +
  • -

#11 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: else if statement,else without if error

Posted 12 October 2012 - 10:17 PM

View Postjon.kiparsky, on 13 October 2012 - 10:34 AM, said:

In this case, I believe there will be no need for last resorts - I have faith in bulletprooftiger's ability to re-format their code.


Dude, tell you what. I think this statement of yours is gonna provide him all the inspiration that he needs to reformat the code. :)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1