Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Factorial Calculator - N! being displayed as 1?

$
0
0
Hey guys, I've been working on an assignment creating a factorial calculator with the psuedo code given. I have followed the following comments and psuedo code given (Basically a factorial calculator using different data types, by clicking different buttons ex. Byte button, short button etc.):

‘Declare static variables MK_n and MK_factorial as Byte.   
‘Display the label “Byte” under the label “Data Type”
MK_n = MK_n + 1
If (MK_n = 1) then 
MK_factorial = 1
Else 
MK_factorial = MK_factorial * MK_n
End If
‘Display the values of MK_n and MK_factorial in the corresponding text boxes.


I have come up with this code:

 
Private Sub AH_Button_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AH_Button_1.Click
        Dim AH_n As Byte
        Dim AH_factorial As Byte
        Dim AH_Textbox_1 As Byte

        AH_Label_5.Text = "Byte"
        AH_n = AH_n + 1
        If AH_n = 1 Then
            AH_factorial = 1
        Else
            AH_factorial = AH_factorial * AH_n
        End If
        AH_TextBox_2.Text = AH_factorial

    End Sub


AH_TextBox1 is supposed to be the N value input by the user, while AH_TextBox2 is supposed to show the final factorial value.

The problem I'm having is that the value of AH_factorial (TextBox2) keeps returning 1 no matter what the N value is.

Can anyone point out the flaw in my code?

Thanks.
Aaron

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>