VS 2013 Help creating Factorials
-
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 intAlso 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
-
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 intAlso 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
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?
- Take the initial number from the user. Lets call the number "Nanny", because "N" is a non-descriptive name.
- Write an X
- Subtract one from Nanny.
- Write down Nanny.
- 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;
- 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[^]
-
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?
- Take the initial number from the user. Lets call the number "Nanny", because "N" is a non-descriptive name.
- Write an X
- Subtract one from Nanny.
- Write down Nanny.
- 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;
- 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[^]
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 !).
-
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 !).
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[^]
-
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 !).
-
I feel dirty.