2014-11-08 100 views
-3
int GetData (int* PR, int* IY, int* NY); 

double monthly_payment (double MP, int PR, double IM, double Q); 

void print_amortization_table (int PR, int IY, double IM, int NY, int NM, double MP); 

int main (void) 
{ 

    int NY;   //number of years 
    int NM;   //number of months 
    int IY;   //interest/year 
    int PR;   //principle 
    double P;  //value of (1+IM)^NM 
    double X;  //value of (1+IM) 
    double Q;  //value of (p/(p-1)) 
    double IM;  //interest/month 
    double MP;  //monthly payment 

    GetData (&PR, &IY, &NY); //call to GetData 

    IM = (IY/12)/100; //calculations 
    X = (1 + IM); 
    NM = (NY * 12); 
    P = pow(X, NM); 
    Q = (P/(P-1)); 

    MP = (PR * IM * Q); //TEMP--- TO BE REMOVED 
    printf("NY  NM  IY  PR  IM  MP\n"); //TEMP--- TO BE REMOVED 
    printf("%d  %d  %d  %d  %lf  %lf\n", NY, NM, IY, PR, IM, MP);  //TEMP--- TO BE REMOVED 
    //monthly_payment (MP, PR, IM, Q);  call to monthly payment 
    //print_amortization_table (PR, IY, IM, NY, NM, MP); call to print_amortization_table 
} 

int GetData (int* PR, int* IY, int* NY) 
{ 

    printf("Amount of the loan (Principle)? "); 
    scanf("%d", &PR); 
    printf("Interest rate/year (percent)? "); 
    scanf("%d", &IY); 
    printf("Number of years? "); 
    scanf("%d", &NY); 
} 
+2

您還沒有發佈的什麼是錯的描述。 – Dai 2014-11-08 03:06:18

+0

順便說一句,我注意到你存儲的利率(通常是一個真正的小數)作爲一個整數。這是故意的嗎? – Dai 2014-11-08 03:07:15

+0

對不起,我是新來的網站,並沒有想太多,我猜。是的,這是故意的,因爲它意味着被讀作百分比。至於什麼是錯誤的整體,當我運行該程序時,所有的數字都非常奇怪。當我在GetData函數中輸入5000,11,1時,打印行顯示「1199870328 1513542048 0 4195523 0.000000 -nan」,並且我找不到我做錯了什麼。 – Tyler 2014-11-08 03:13:40

回答

3

由於you'v已經通過地址作爲參數傳入函數的GetData,所以你需要更換你的函數:

int GetData (int* PR, int* IY, int* NY) 
{ 
    printf("Amount of the loan (Principle)? "); 
    scanf("%d", PR); //PR is the address already 
    printf("Interest rate/year (percent)? "); 
    scanf("%d", IY); //IY is the address already 
    printf("Number of years? "); 
    scanf("%d", NY); //NY is the address already 
}