Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. VS 2013 Help creating Factorials

VS 2013 Help creating Factorials

Scheduled Pinned Locked Moved Visual Studio
helptutorialcssvisual-studio
6 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11464236
    wrote on last edited by
    #1

    This is for my programming class. Here is the assignment my teacher gave me:

    I need help creating a VB program using factorials

    Here are the instructions:

    Factorials are used to calculate combinations of things in statistics. The factorial of an integer is the product of that integer times all positive numbers less than itself. For example 5 factorial is:

    5 * 4 * 3 * 2 * 1 or 120.

    The symbol for factorials is the exclamation point, so 5 factorial is written like this:

    5!

    By the way, we programmers call the exclamation point a bang. So we would say “5 bang” to describe this. Just another reason to become a programmer. Cool jargon.

    In statistics, factorials are used to calculate permutations and combinations. For example, the odds of getting a particular poker hand can be calculated using factorials.

    As a gambling craze has hit downtown Rome and the Romans are as innumerate as ever, you have decided to help them calculate factorials. Your program will look simple. The Roman will enter an integer, and you will display the factorial of that integer. One problem you need to consider is that factorials get very large very quickly. It doesn’t take a very large integer to have a very large factorial. You need to figure out how large an integer can be held in a VB integer variable and check that you don’t enter a number that’s too large. You will also need to know how to construct a loop. Three loop constructs exist that you can use (you only need one of these):

    Do While

    Do Until

    For – Next

    Before you start your program you consult with a mathematician who informs you that the factorial of zero is 1, and that there is no such thing as factoring a negative number. You thank her and decide to put these checks in your program.

    You will also need to use the integer data type instead of the decimal data type. Variables of type integer can only hold whole numbers – no fractions. They are declared like this:
    Dim intFactorial as int

    Also the integer.tryparse function will probably be useful. Integer.tryparse does what you would expect it to do.

    Here is what I have so far:

    Dim A As Integer
    Dim Success1 As Boolean
    A = (TxtNmbrBox.Text = "")
    Success1 = Integer.TryParse(TxtNmbrBox.Text, A)

        If Not Success1 Then
            MsgBox("Please Enter A Number In Box")
            TxtNmbrBox.Text = ""
            LblAb.Text = ""
            Exit Sub
    
    L 1 Reply Last reply
    0
    • U User 11464236

      This is for my programming class. Here is the assignment my teacher gave me:

      I need help creating a VB program using factorials

      Here are the instructions:

      Factorials are used to calculate combinations of things in statistics. The factorial of an integer is the product of that integer times all positive numbers less than itself. For example 5 factorial is:

      5 * 4 * 3 * 2 * 1 or 120.

      The symbol for factorials is the exclamation point, so 5 factorial is written like this:

      5!

      By the way, we programmers call the exclamation point a bang. So we would say “5 bang” to describe this. Just another reason to become a programmer. Cool jargon.

      In statistics, factorials are used to calculate permutations and combinations. For example, the odds of getting a particular poker hand can be calculated using factorials.

      As a gambling craze has hit downtown Rome and the Romans are as innumerate as ever, you have decided to help them calculate factorials. Your program will look simple. The Roman will enter an integer, and you will display the factorial of that integer. One problem you need to consider is that factorials get very large very quickly. It doesn’t take a very large integer to have a very large factorial. You need to figure out how large an integer can be held in a VB integer variable and check that you don’t enter a number that’s too large. You will also need to know how to construct a loop. Three loop constructs exist that you can use (you only need one of these):

      Do While

      Do Until

      For – Next

      Before you start your program you consult with a mathematician who informs you that the factorial of zero is 1, and that there is no such thing as factoring a negative number. You thank her and decide to put these checks in your program.

      You will also need to use the integer data type instead of the decimal data type. Variables of type integer can only hold whole numbers – no fractions. They are declared like this:
      Dim intFactorial as int

      Also the integer.tryparse function will probably be useful. Integer.tryparse does what you would expect it to do.

      Here is what I have so far:

      Dim A As Integer
      Dim Success1 As Boolean
      A = (TxtNmbrBox.Text = "")
      Success1 = Integer.TryParse(TxtNmbrBox.Text, A)

          If Not Success1 Then
              MsgBox("Please Enter A Number In Box")
              TxtNmbrBox.Text = ""
              LblAb.Text = ""
              Exit Sub
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It would have been nice if the mathematician also explained the steps to get to a factorial. The example given in the text is kinda useless, Wikipedia has a decent example[^]. So, if the Roman enters 3 (!), the output should be 3x2x1? Or 6? ..that means you'd do these steps, over and over?

      1. Take the initial number from the user. Lets call the number "Nanny", because "N" is a non-descriptive name.
      2. Write an X
      3. Subtract one from Nanny.
      4. Write down Nanny.
      5. If Nanny is not 0, repeat from step 2.

      If you'd need to calculate it, you'd do the actual steps, as opposed to writing them to screen;

      1. Multiply Nanny by (Nanny-1) until Nanny equals 0

      Member 11498570 wrote:

      we programmers call the exclamation point a bang.

      Ehr.. no, you'll find that most would nowadays pronounce it as "not" and call it an exclamation-mark. Anyway, Chr(33) will do just fine.

      Member 11498570 wrote:

      Integer.tryparse does what you would expect it to do.

      Yeah, it gets you a warning to decently capitalize your code.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      P 1 Reply Last reply
      0
      • L Lost User

        It would have been nice if the mathematician also explained the steps to get to a factorial. The example given in the text is kinda useless, Wikipedia has a decent example[^]. So, if the Roman enters 3 (!), the output should be 3x2x1? Or 6? ..that means you'd do these steps, over and over?

        1. Take the initial number from the user. Lets call the number "Nanny", because "N" is a non-descriptive name.
        2. Write an X
        3. Subtract one from Nanny.
        4. Write down Nanny.
        5. If Nanny is not 0, repeat from step 2.

        If you'd need to calculate it, you'd do the actual steps, as opposed to writing them to screen;

        1. Multiply Nanny by (Nanny-1) until Nanny equals 0

        Member 11498570 wrote:

        we programmers call the exclamation point a bang.

        Ehr.. no, you'll find that most would nowadays pronounce it as "not" and call it an exclamation-mark. Anyway, Chr(33) will do just fine.

        Member 11498570 wrote:

        Integer.tryparse does what you would expect it to do.

        Yeah, it gets you a warning to decently capitalize your code.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        I'd also expect it to complain that there's no Integer type available (and the bang thing shows a definite Unix background - this was a common way of the dungaree-wearers referring to the !).

        L Richard DeemingR 2 Replies Last reply
        0
        • P Pete OHanlon

          I'd also expect it to complain that there's no Integer type available (and the bang thing shows a definite Unix background - this was a common way of the dungaree-wearers referring to the !).

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Pete O'Hanlon wrote:

          I'd also expect it to complain that there's no Integer type available

          Missed that one :(

          Pete O'Hanlon wrote:

          and the bang thing shows a definite Unix background

          Posters on the wall don't count.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • P Pete OHanlon

            I'd also expect it to complain that there's no Integer type available (and the bang thing shows a definite Unix background - this was a common way of the dungaree-wearers referring to the !).

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Pete O'Hanlon wrote:

            I'd also expect it to complain that there's no Integer type available

            The code appears to be VB.NET, where Integer[^] is an alias for Int32.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            P 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Pete O'Hanlon wrote:

              I'd also expect it to complain that there's no Integer type available

              The code appears to be VB.NET, where Integer[^] is an alias for Int32.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              I feel dirty.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups