Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net (Visual Basic)整数与2个数之和_Vb.net_Loops - Fatal编程技术网

Vb.net (Visual Basic)整数与2个数之和

Vb.net (Visual Basic)整数与2个数之和,vb.net,loops,Vb.net,Loops,所以我非常接近,但我继续得到错误的值。假设用户输入一个正整数,并将中间的所有整数相加。因此,如果用户输入5,它应该等于15,10将等于55,等等,但我得到5=25,10,100 更改为decimal,以查看它是否有任何内容而不是整数,并且仍然没有任何内容。我看到了一些设置decCount为=1的东西。这样做了,数字更接近,但仍然不存在 Dim decSum As Decimal = 0 Dim decNumber As Decimal = 0 Dim decCount A

所以我非常接近,但我继续得到错误的值。假设用户输入一个正整数,并将中间的所有整数相加。因此,如果用户输入5,它应该等于15,10将等于55,等等,但我得到5=25,10,100

更改为decimal,以查看它是否有任何内容而不是整数,并且仍然没有任何内容。我看到了一些设置decCount为=1的东西。这样做了,数字更接近,但仍然不存在

    Dim decSum As Decimal = 0
    Dim decNumber As Decimal = 0
    Dim decCount As Decimal = 0
    Dim strUserInput As String

    strUserInput = InputBox("Enter a positive integer value.", "Input Needed", 0)


    If Decimal.TryParse(strUserInput, decNumber) And (decNumber >= 0) Then
        Do While decCount < decNumber
            decSum = decSum + decNumber
            decCount = decCount + 1
        Loop
    Else
        MessageBox.Show("Enter a positive numeric value")
    End If




    MsgBox("The sum of the numbers 1 through " & decNumber & " is " & decSum)
Dim decSum作为十进制=0
十进制数字=0
十进制的Dim decCount=0
作为字符串的Dim strUserInput
strUserInput=InputBox(“输入一个正整数值。”,“需要输入”,0)
如果Decimal.TryParse(strUserInput,decNumber)和(decNumber>=0),则
decCount
您试图计算给定输入的阶乘,但在循环中重复添加相同的数字(实际上,您是将数字本身相乘,而不是查找阶乘)

更改此行:

decSum=decSum+decNumber

为此:


deccum=deccum+decCount

哇……这就解释了这么多。非常感谢。此外,我还忘了在decCount