Link to home
Start Free TrialLog in
Avatar of Nicholas Stephenson
Nicholas Stephenson

asked on

Loop goes into infinity

The task is to find the withdrawal amount necessary that when taken from the bank balance and when fees are applied the total fees + the withdrawal amount should equal to the bank balance so that there's nothing left. That withdrawal amount should then be displayed.

The thing is I've tried structuring the loop several ways but it still results in an infinite loop without producing the correct results.

[code]

Public conversionCost As Double = 0.035
Public atmFee As Double = 3.15

     'Calculates the maximum amount you can withdraw from current balance
    Public Sub FullDraw(ByVal flFee As Double, actBal As Double, excRate As Double)

        Dim withdrawalAmt As Double

        'redact atmfee first from current balance
        withdrawalAmt = actBal - atmFee


        'Loop until figures match to find the perfect withdrawal amount that doesn't
        'leave money behind

        Dim finalAmt As Double

        Do Until finalAmt = actBal

            withdrawalAmt -= 1

            'calculate possible conversion fee so it can be included
            Dim conversionFee As Double = conversionCost * withdrawalAmt

            'add fee

            finalAmt = withdrawalAmt + conversionFee

        Loop


           Label3.Text = withdrawalAmt

    End Sub
SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question was answered..

Sara