I gotta finish this application. When the "Enter Numbers" button is clicked, the application displays an input box for the user to insert an integer. After the number has been typed and the OK button is clicked, the application is supposed to give out the sum of all integers from 1 to the value entered by the user.
Example: If the value entered is 5, the sum will be 15; if it's 10 it'll be 55
This is my code but something's obviously wrong, it is maybe in the loop?
If you could help me out asap, I'd appreciate it a lot.
The result I get for 5 is 25, and for 10 is 100!
Also, could you tell me how to display the result in a message box?
Thank u
Example: If the value entered is 5, the sum will be 15; if it's 10 it'll be 55
This is my code but something's obviously wrong, it is maybe in the loop?
If you could help me out asap, I'd appreciate it a lot.
VB.NET:
Dim strUserInput As String
Dim intcount As Integer
Dim decamount As Integer
Dim dectotal As Decimal
intcount = 1
dectotal = 0
strUserInput = InputBox("Enter a positive integer value." & intcount.ToString(), "Input Needed", "10")
Do While intcount <= strUserInput
If strUserInput >= 1 Then
decamount = CInt(strUserInput)
dectotal += decamount
intcount += 1
ElseIf strUserInput <= 0 Then
MessageBox.Show("Enter a positive number", "Error", MessageBoxButtons.OK)
End If
Loop
The result I get for 5 is 25, and for 10 is 100!
Also, could you tell me how to display the result in a message box?
Thank u