วันพุธที่ 9 กันยายน พ.ศ. 2558

Lab04 : Loan

//nf(variable ,left digit , right digit)
void setup(){
  loan(5000,0.12,1); //5000baht 12percent 1year
}

void loan(float amt,float rate,int yr){
  int month=yr*12;
  float ratepm=rate/12; // rate per month per year
  float ppm=amt * ( ratepm / (1 - pow(1 + ratepm,-month))); //pay per month  (pri+interest)
  float pri=ppm; // principal
  float unpaid=amt; // unpaid
  float total_interest=0;
  int i=1;
  println("No. Interest Principal  Unpaid   total interest");
  while (i<=month){
   print(nf(i,2));//NO.
   print("    "+nf(ratepm*unpaid, 2,2));//interest 
   total_interest+=ratepm*unpaid; 
   pri=ppm-(ratepm*unpaid); 
   unpaid-=pri; 
   if (unpaid<0)unpaid=0;
   print("   "+nf(pri,3,2)); // principal 
   print("    "+nf(unpaid,4,2)); // unpaid 
   print("      "+nf(total_interest ,3,2)); //total_interest
   println();
   i++;
  }
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...