Results 1 to 3 of 3
  1. #1
    jaki312 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default how to make program that keeps score and loops till XXX is inputed

    hi can some1 pls help me out im trying to make a program that loops till you type in xxx. i got that part done but the main goal of the program is that you need to type in a word and then the following word's first letter should start with the previous word's last letter for e.g. input:hello input:over input:rare input:xxx
    output:score:3
    if the word doesnt start with the previous word last letter it is counted as incorrect and if it starts with the last letter it is correct
    later on the score = correct - incorect to get score here is my code pls help me out im strugling bad with this program

    here is code
    Java Code:
    String bgnword = JOptionPane.showInputDialog("Enter a begin word: ");
            int score;
            int len = bgnword.length();
            score = 0;
            String word;
            int corwrd = 0;
            int incwrd = 0;
            String prevword = null;
            while(!"XXX".equals(word = JOptionPane.showInputDialog("Enter a word or XXX to quit.")))
            {
                char bgn = bgnword.charAt(len - 1);
                
                
                prevword = word;
                
                int len2 = word.length();
                char ch1 = word.charAt(0);         
                char ch2 = prevword.charAt(len2 - 1);
                if (prevword != null)
                {
                    if(ch1 == ch2)
                    {
                        corwrd++;
                    }
                    else
                    {
                        incwrd--;
                    }
                    score = corwrd - incwrd;
                    
                }
            }
                         
            System.out.println("Score: " + score);
    Last edited by Norm; 03-13-2012 at 08:07 PM. Reason: added code tags

  2. #2
    jaki312 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default Re: how to make program that keeps score and loops till XXX is inputed

    can any1 pls help me on this 1

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: how to make program that keeps score and loops till XXX is inputed

    Please execute the program and Post the program's output here.
    Add comments to the output saying what is wrong with it and show what the output should be.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Last edited by Norm; 03-13-2012 at 08:09 PM.

Similar Threads

  1. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  2. Replies: 4
    Last Post: 02-15-2011, 11:05 PM
  3. Replies: 9
    Last Post: 11-01-2009, 05:45 AM
  4. Basic high score program
    By Implode in forum New To Java
    Replies: 5
    Last Post: 09-03-2009, 05:21 PM
  5. Help combining loops into 1 program.
    By kewlgeye in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 09:58 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
  •