Hi there everyone
Sorry for the long explanation…
I’m trying to simulate a 6 month credit card statement where the user pays only the minumum due (or 10.00 which ever is more) for six months. If they spend less than 50.78, their balance will hit 0 by 6 months. I want to write a loop that calculates the interest and new balance every month for 6 months. If the balance reaches 0 before 6 months, I need the loop to stop executing. I’m really gummed up in the head about this. I’ve tried doing it long-hand but the nesting for loops boggle me.
Below is sort of what I want to calculate, but I want it to stop if the amount gets into the negative numbers. I’ve tried writing it with a million nested if statements but I start to get pretty confused.
//the allPurchases number is really produced dynamically through some fake virtual shopping
allPurchases=6;
month1=allPurchases;
PRFC=.049827;
month1=Number((_root.allPurchases*PRFC)+_root.allPurchases)-10.00;
trace(month1);
if((month1==0)||(month1<0)){
trace("month1 is nothing");
}
month2=Number((month1*PRFC)+month1)-10.00;
trace(month2);
if((month2==0)||(month2<0)){
trace("month2 is nothing");
}
month3=Number((month2*PRFC)+month2)-10.00;
trace(month3);
if((month3==0)||(month3<0)){
trace("month3 is nothing");
}
month4=Number((month3*PRFC)+month3)-10.00;
trace(month4);
if((month4==0)||(month4<0)){
trace("month4 is nothing");
}
month5=Number((month4*PRFC)+month4)-10.00;
trace(month5);
if((month5==0)||(month5<0)){
trace("month5 is nothing");
}
month6=Number((month5*PRFC)+month5)-10.00;
trace(month6);
if((month6==0)||(month6<0)){
trace("month6 is nothing");
}
month6Round=int((month6)*100)/100;
trace(month6Round);
Here’s the way I imagine it sort of should look but I know is completely wrong:
allPurchases=6;
month1=allPurchases;
PRFC=.049827;
if(month1<50.78){
i=0;
for(i=1;i<6;i++){
//initial calculation for first month where they make a payemnt but have not yet been charged interest
month1=Number((allPurchases*PRFC)+allPurchases)-10.00;
trace(month1);
//if they hit zero right off the bat in the first month don;t do anymore
if(month1<1){
i+=0;
trace("month1 is nothing");
//start checking subsequent months
}else if (month1>0){
while(this["month"+i]>0){
i+=1;
Number((this["month"+i]*PRFC)+this["month"+i])-10.00;
}
}
}
}
I’ve re-written this a million different ways and I’m getting no where! Please someone,help end my misery!