---
# System prepended metadata

title: HW2024

---

# HW2024
```
#include <stdio.h>
#include <stdint.h>
#include <math.h>

int main(){
    int32_t Price=0,Term=0,Rate=0,Tax=0,Ins=0,AddPay=0;
    printf("$ ./hw0204\n");
    char Date[7];

    printf("Loan Date: ");
    scanf("%s",Date);
    int32_t yr=((int)Date[0]-(int)'0')*1000+((int)Date[1]-(int)'0')*100+((int)Date[2]-(int)'0')*10+((int)Date[3]-(int)'0');
    int32_t mn=((int)Date[5]-(int)'0')*10+((int)Date[6]-(int)'0');

    printf("Loan Price: ");
    scanf("%d",&Price);
    printf("Loan Term (yrs): ");
    scanf("%d",&Term);
    printf("Interest Rate (%): ");
    scanf("%d",&Rate);
    printf("Property Tax (/m): ");
    scanf("%d",&Tax);
    printf("Insurance (/m): ");
    scanf("%d",&Ins);
    printf("Additional Payment (/m): ");
    scanf("%d",&AddPay);
    double m,p,r,n;
    p=Price;
    r=(double)Rate/1200;
    n=(double)Term*12;
    m=p*((r * pow((r+1.00),n)  )/
            ( pow((r+1.00),n) - 1.00  ));
 //   printf("%f\n%f\n%f\n%f\n",p,r,n,m);
    int32_t tmp=(int)m+Tax+Ins;
    printf("--- Output ---\n");
    printf("Total monthly payment: %d\n",tmp);
    double Principal=0,Interest=0,Remaining=Price ;

    for(int i=0;i<3;i++){
        Principal = AddPay + (int)m - Remaining * r ;
        Interest = (int)m-Principal;
        Remaining = Remaining - Principal;
        mn++;
        if(mn>12){
            mn=1;
            yr++;
        } 
        double pr=(int)(Principal*100+0.5)/100.0;
        double in=(int)(Interest *100+0.5)/100.0;
        double re=(int)(Remaining*100+0.5)/100.0;
        if(mn>=10){
            printf("%d.%d) ",yr,mn);
        }else{
            printf("%d.0%d) ",yr,mn);
        }
        
        printf("%.2lf\n",pr);
        if(pr>1e3){
            if(pr>1e6){
                if(pr>1e9){
                    ((int)pr/(int)1e9);
                }
                ((int)pr/(int)1e6)-((int)pr/(int)1e9)*1000;
            }
                ((int)pr/(int)1e3)-((int)pr/(int)1e6)*1000;
        }
        pr- ((int)pr/(int)1e3);

        printf("%.2lf\n",in);
        printf("%.2lf\n",re);

    }
    
    return 0;
}
```