[英]Nothing happens when I run program
The guys just helped me with a problem, got solved 100%, but now I have another one. 你们只是帮我解决了一个问题,得到了100%的解决,但是现在我有了另一个。
I compile my files and everything without problems, but when i want to run the program nothing happens. 我编译文件和所有内容都没有问题,但是当我想运行程序时,什么也没发生。
enter.c : http://pastebin.com/GGzVeAhw simple_interest.c: http://pastebin.com/XdESrxSk enter.c: http ://pastebin.com/GGzVeAhw simple_interest.c: http ://pastebin.com/XdESrxSk
This is how my header file looks like: 这是我的头文件的样子:
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 This forum is really helpful, especially for a beginner like me. PS:这个论坛真的很有帮助,特别是对于像我这样的初学者。
You have a bunch of prototypes in main()
, but no function call. 您在main()
有一堆原型,但是没有函数调用。
It should be: 它应该是:
int main(void)
{
enter();
return 0;
}
You seem really confused about how to declare and use functions, perhaps you need some tutorial? 您似乎对如何声明和使用函数感到困惑,也许您需要一些教程?
simple_interest.h 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 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 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;
}
compile like this way 这样编译
gcc sample.c simple_interest.c
./a.out
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.