2014-02-21 75 views
0

這些傢伙幫我解決了一個問題,100%解決了,但現在我又有了一個。當我運行程序時沒有任何反應

我編譯我的文件和一切都沒有問題,但是當我想運行該程序沒有任何反應。

enter.c:http://pastebin.com/GGzVeAhw simple_interest.c:http://pastebin.com/XdESrxSk

這是我的頭文件看起來像:

int enter(void); 
double Calc_Interest(double principal, double rate, int term); 
double Calc_Amount(double principal, double interest); 
double Calc_Payments(double total, int term); 
void Display_Results(double principal, double interest, double total, double mPay); 

PS本次論壇是真正有用的,特別是對於像我這樣的初學者。

+1

從你的'主()'調用相應的功能(S)。 – Rohan

+0

您不是**從'main'調用**這些函數。您只添加了他們的聲明。 – Groo

回答

1

你有一堆原型main(),但沒有函數調用。

它應該是:

int main(void) 
{ 
    enter(); 
    return 0; 
} 

你看起來真搞不清楚如何聲明和使用功能,也許你需要一些教程?

+0

我知道。剛開始uni,我不得不參加編程課程,我從來沒有編程過。但我的兄弟會幫助我。現在只需要幫助...但非常感謝。 – Mat

0

simple_interest.h

int enter(void); 
double Calc_Interest(double principal, double rate, int term); 
double Calc_Amount(double principal, double interest); 
double Calc_Payments(double total, int term); 
void Display_Results(double principal, double interest, double total, double mPay); 

simple_interest.c

//Implement all functions in this file 
#include <stdio.h> 

double Calc_Interest(double principal, double rate, int term) 
{ 
     double interest; 
     interest = principal * (rate/100) *term; 

     return interest; 
} 

double Calc_Amount(double principal, double interest) 
{ 
     double total; 
     total = principal + interest; 

     return total; 
} 

double Calc_Payments(double total, int term) 
{ 
     double mPay; 
     mPay= total/(12 * term); 

     return mPay; 
} 
void Display_Results(double principal, double interest, double total, double mPay) 
{ 
     printf("\n"); 
     printf("Personal Loan Statement\n"); 
     printf("\n"); 
     printf("Amount Borrowed: %.2f\n" , principal); 
     printf("Interest on Loan: %.2f\n" , interest); 
     printf("--------------------------------------------------------------------------------\n"); 
     printf("Amount of Loan: %.2f\n" , total); 
     printf("Monthly Payment: %.2f\n" , mPay); 

} 

sample.c文件

#include <stdio.h> 
#include "simple_interest.h" 

int enter(void) 
{ 
     double principal, rate, interest, total, mPay; 
     int term; 

     printf("--------------------------------------------------------------------------------\n"); 
     printf("This program calculates the monthly payments due from a personal loan\n"); 
     printf("--------------------------------------------------------------------------------\n"); 

     printf("Enter amount of the loan: "); 
     scanf("%lf", &principal); 

     printf("Enter current annual interest rate in \n"); 
     scanf("%lf", &rate); 

     printf("Enter the number of years of the loan: "); 
     scanf("%d", &term); 

     interest = Calc_Interest(principal, rate, term); 
     total = Calc_Amount(principal, interest); 
     mPay = Calc_Payments(total, term); 

     Display_Results(principal, interest, total, mPay); 

     return 0; 
} 

int main(void) 
{ 
     enter(); 
     return 0; 
} 

編譯像這樣

gcc sample.c simple_interest.c 
./a.out 
相關問題