Solved

# Looping based upon a double value not an integer value

Posted on 2007-08-02
137 Views
I think I just need someone smarter or more experienced to help me see how to solve this.  Sometimes I wonder if I have the "mental" prowess to be a software developer...LOL.  I feel like a dummy sometimes.  Maybe talking this out will help me find the answer.  Discussion is always a good idea for these matters.  :)

I have an enumeration I am using to determine amortization periods, as follows:

public class CommonFinancedItems
{
private AmortizationPeriodType _amortType;

public CommonFinancedItems()
{
}

#region enums

public enum AmortizationPeriodType : int
{
Weekly = 52,
BiWeekly = 24,
Monthly = 12
}
public AmortizationPeriodType AmortPeriod
{
get
{
return _amortType;
}
set
{
_amortType = value;
}
}

#endregion

}

elsewhere in my program my intent is to use these enumerations to determine HOW OFTEN a payment is to be made.  I have two objects, one is for Mortgage (M) and one is for Heloc (H)  --  Heloc represents "Home Equity Line of Credit".  Basically....it boils down to 2 seperate interest-bearing loans that need to be paid-off.  The trick is...the H is used to pay down large chunks of the principle on the M.  The idea is...you can pay down a mortgage faster if you are applying payments, big payments, to the principal every so often.  Make sense?

Okay....so now my "problem" is ... while only  ONE   payment is being made on the Mortgage every month, there are going to be either 1, 2 or 4.33 (repeating decimal) H payments for EACH Mortgage payment.  This does not seem to lend itself to a for loop very nicely.  I could just truncate the Weekly payments to just 4 but that seems wrong...

Is my question making sense?

Say it was Weekly payments  (52 divided by 12 is 4.33 repeating)

for(i=0;i < 4.33;I++)  {  }  can't do that
0
Question by:knowlton

LVL 96

Expert Comment

You could probably get away with a while statement:

double d = 0;
while (d < 4.33)
{
}

Bob
0

LVL 5

Author Comment

I'll see if I can make that work!

Thanks!
0

LVL 96

Accepted Solution

Or, you could do this:

for(double d=0;d< 4.33;d += .33)
{
}

Bob
0

LVL 5

Author Comment

I ended-up figuring-out how much the amortized amount would be, then, each time a payment was made I accrued that to an accumulator.  Once the accumulator was >= the original un-amortized amount (the monthly amount) I then allow a mortgage payment to be made.
0

## Featured Post

### Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…