Results 1 to 3 of 3

Thread: Problem with finding prime numbers and making it divisible

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Problem with finding prime numbers and making it divisible

    I am trying to make a program that if the user inputs a prime number then the program can help make it a divisible number by increasing it by 1 and if it becomes divisible then the label 1.Text will show that number. But i cant seem to find an answer

    VB.Net Code:
    1. Public Class Form1
    2.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    3.         Dim Ans As Integer = CInt(txtPrime.Text)
    4.         Dim newAns As integer
    5.        For b = 2 To Ans
    6.        If Ans Mod b = 0 Then
    7.                 Label1.Text = Ans
    8.             End If
    9.             If Ans Mod b > 0 Then Exit For
    10.             newAns = Ans + 1
    11.             Label1.Text = newAns
    12.         Next b
    Last edited by FunkyDexter; Apr 13th, 2018 at 06:21 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,305

    Re: Problem with finding prime numbers and making it divisible

    Can you explain the logic (specific, not just find a prime number) that your code is supposed to be implementing? You should be able to write down as a series of steps. You should then be able to explain exactly how the code you have implements those steps.

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Problem with finding prime numbers and making it divisible

    I added code tags to make your post more readable. You can find these at the top of the posting window. It's the button marked # or VB - depending on how you want your code to appear.

    As JM has said, it will help a lot if you sit down and work out the steps to carry out the task using a pen and paper - NOT code. Code comes second, after you're 100% sure you know how to solve the problem. In your case I suggest you give thought to when you exit your loop and why.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

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



Click Here to Expand Forum to Full Width