Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inclusive Number program not quite working right

    This program is working not quite right. now this program is supposed to input five number, and check for any duplication and if there is duplication, it will not show the number. also the number must be between 10 and 100 inclusive. If i enter any number below 10, then it works great, but enter any number after 10, and I can't get it to go to the next input and move forth on. This is what I got:
    Code:
    
    Enter array:
    20
    Number entered:
    0 21Number entered:
    0 21Press any key to continue...
    Code:
      // compare input number to unique numbers in array
              for ( int i = 0; i < counter; i++ )
    
                 // if new number is duplicate, do nothing
                 if ( number == array[ i ] )
                    return;
    
              // append new number to text area
              output.append( " " + number );
    
              // store new and unique number
              array[ counter++ ] = number;
           }
           else
              showStatus( "Number entered exceed 5." );
    
        }  // end method actionPerformed
    
    }  // end class Unique

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any Suggestion? Anyone?

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How long is the entire program? From what you say it probably isn't that long and you should post the whole thing. In any case, you have to post more code to get any answers. There just isn't enough there for me to help find the problem.

    david_kw

  • #4
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    I agree that it's hard to get a good feel for what your issue might be given the minimal code you've provided. However, I will point out one thing that may be an issue.

    You don't have any { } for you're for-loop but it looks like (based on the code) that you might want them

    If you want more than one operation to be performed in your loop, you need to surround these with brackets. At present your loop should only be performing that following.

    Code:
    for ( int i = 0; i < counter; i++ )
    
                 // if new number is duplicate, do nothing
                 if ( number == array[ i ] )
                    return;
    If you intended your output.append line to be executed for each iteration of the loop you'll need some brackets.

    Code:
    for ( int i = 0; i < counter; i++ )
    {
                 // if new number is duplicate, do nothing
                 if ( number == array[ i ] )
                    return;
    
              // append new number to text area
              output.append( " " + number );
    
              // store new and unique number
              array[ counter++ ] = number;
    }


  •  

    Posting Permissions

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