Results 1 to 13 of 13
  1. #1
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default Need help with a program!

    I need to add all the prime numbers below an arbitrary number.
    Last edited by cid; 07-01-2010 at 12:59 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Do you see what I am doing wrong?
    Yes, you are not replying to the three helpful responses given to you in your previous thread. Many here feel that if you don't acknowledge that you've read previous help, why should they help you in the future?

  3. #3
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    sorry fubarable we have an understanding now

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,512
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cid View Post
    I can't use the % option.
    Why not? Did your dog chew on the % key?

    kind regards,

    Jos

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    I can't use the % option
    Is that a requirement from the instructor: you can not use the modulus operator?

    What is your algorithm for determining if a number is prime? Not the definition, a list of steps to determine it.

  6. #6
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    yes, it is a requirement. the way i will find out if a number has a remainder is to multiply by two times the divisor and subtract that from the number.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    So how is the project doing then?

  8. #8
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    horribly. man
    Last edited by cid; 07-01-2010 at 01:00 PM.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    Try debugging your code by printing out each number it tests and show whether that number is prime or not.

  10. #10
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    tried debugging
    Last edited by cid; 07-01-2010 at 01:00 PM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    Do the following:
    Try debugging your code by printing out each number it tests and show whether that number is prime or not.

    Where is the answer to this question?
    What is your algorithm for determining if a number is prime?

  12. #12
    cid
    cid is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    in order to find out if the number is prime using integers i am subtracting the quotient*divisor from the dividend. if the result is >0 in every instance i am trying to make the program understand that the number is prime and to add it to the sum. if the result of dividend-quotient*divisor is 0 then i want the program to skip that number and not add it to the sum.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    Are you able to understand the following request:
    Try debugging your code by printing out each number it tests and show whether that number is prime or not.

    Also print out the values of the quotient, divisor and dividend.
    Last edited by Norm; 07-01-2010 at 02:54 AM.

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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