i use vb 6.0
[CODE=vb]
Option Explicit
Dim Error As Double
Dim x As Integer
Dim y As Double
Dim z As Integer
Dim eps As Double
Dim N As Integer
Private Sub cmdCalculate_Cl ick()
'user input
If IsNumeric(txtN) And IsNumeric(txtEp s) And IsNumeric(txtX) Then
N = txtN.Text
eps = txtEps.Text
x = txtX.Text
Else
MsgBox "all input must be numeric", vbExclamation, "numeric test"
txtN.SetFocus
End If
'calculate
Do
y = (x) - (x - (N ^ (1 / 2)))
Error = y - x
If Error < 0 Then
Error = Error * -1
End If
z = z + 1
Loop Until Error < eps
'display the result
lblDisplay.Capt ion = "root : " & y & " iteration : " & z
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
[/CODE]
the problems..
the 'eps' is the decimal places.in my program above it need user to insert the number of decimal places like this '0.001'.. but actually i just want the user put the value as '3'...
the iteration value must be in integer data type as the result of number of looping it takes to complete the loop.. the number of looping (iteration) didn't match its actually value..
[CODE=vb]
Option Explicit
Dim Error As Double
Dim x As Integer
Dim y As Double
Dim z As Integer
Dim eps As Double
Dim N As Integer
Private Sub cmdCalculate_Cl ick()
'user input
If IsNumeric(txtN) And IsNumeric(txtEp s) And IsNumeric(txtX) Then
N = txtN.Text
eps = txtEps.Text
x = txtX.Text
Else
MsgBox "all input must be numeric", vbExclamation, "numeric test"
txtN.SetFocus
End If
'calculate
Do
y = (x) - (x - (N ^ (1 / 2)))
Error = y - x
If Error < 0 Then
Error = Error * -1
End If
z = z + 1
Loop Until Error < eps
'display the result
lblDisplay.Capt ion = "root : " & y & " iteration : " & z
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
[/CODE]
the problems..
the 'eps' is the decimal places.in my program above it need user to insert the number of decimal places like this '0.001'.. but actually i just want the user put the value as '3'...
the iteration value must be in integer data type as the result of number of looping it takes to complete the loop.. the number of looping (iteration) didn't match its actually value..
Comment