这些家伙只是帮我解决了一个问题,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这个论坛真的很有帮助,特别是像我这样的初学者。
答案 0 :(得分:1)
你在main()
中有一堆原型,但没有函数调用。
应该是:
int main(void)
{
enter();
return 0;
}
你似乎对如何声明和使用函数感到困惑,也许你需要一些教程?
答案 1 :(得分:0)
简单兴趣.a
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);
简单兴趣。
//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