?
Solved

Looping based upon a double value not an integer value

Posted on 2007-08-02
4
Medium Priority
?
139 Views
Last Modified: 2010-04-15
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
Comment
Question by:Tom Knowlton
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19619626
You could probably get away with a while statement:

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

Bob
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 19619720
I'll see if I can make that work!

Thanks!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19619732
Or, you could do this:

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

Bob
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 19621277
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question