프로그램을 실행하려했지만 올바르게 실행되지 않았습니다. 문제는 함수에서 발생하지만 정확한 위치를 모른다. 먼저 함수를 선언 한 다음 주 함수로 호출하려고했습니다. 그러나, 나는 그것이 사실인지 모른다. 문제는 함수 정의에 있다고 생각합니까? 그러나 나는 그 밖에 할 일이 없다. 누구든지 그것을보고 나에게 그것을 지적하면 좋을 것입니다.내 코드의 기능이 작동하지 않습니다.
#include <stdio.h>
#include <math.h>
float computeMonthlyPayment(float p, float YearRate, float YearTerm);
float computeMonthlyInterest(float p, float YearRate);
void printLoanInfo(float p, float MonthlyPayment, float YearRate, float r, float YearTerm, float n);
void printTable(float MonthlyPayment, float p, float YearRate,float YearTerm);
int main()
{
float n, p, r, MonthlyPayment, YearRate, YearTerm;
printf("Enter the loan amount: ");
scanf("%f", &p);
if (p <= 0.0)
printf("\nERROR: Invalid rate; must be greater than 0\n");
while (p <= 0.0)
{
printf("\nEnter the loan amount: ");
scanf("%f", &p);
}
printf("\nEnter annual interest rate: ");
scanf("%f", &YearRate);
if (YearRate <= 0.0 || YearRate > 30.0)
printf("\nERROR: Invalid rate; must be > 0.0 amd <= 30.0.\n");
while (YearRate <= 0.0 || YearRate > 30.0)
{
printf("\nEnter annual interest rate: ");
scanf("%f", &YearRate);
}
printf("\nEnter the term of the loan (in years): ");
scanf("%f", &YearTerm);
if (YearTerm <= 0.0)
printf("\nERROR: Invalid rate; must be greater than 0\n");
while (YearTerm <= 0.0)
{
printf("\nEnter the term of the loan (in years): ");
scanf("%f", &YearTerm);
}
float computeMonthlyInterest(float p, float YearRate);
float computeMonthlyPayment(float p, float YearRate, float YearTerm);
void printLoanInfo(float p, float MonthlyPayment, float YearRate, float r, float YearTerm, float n);
return 0;
}
float computeMonthlyPayment(float p, float YearRate, float YearTerm)
{
float r = YearRate/12;
float n = YearTerm*12;
float MonthlyPayment = 0;
MonthlyPayment = (r*p)/1-((1+r)/n);
return MonthlyPayment;
}
float computeMonthlyInterest(float p, float YearRate)
{
float r = 0;
r = ((YearRate)/12)/12;
return r;
}
void printLoanInfo(float p, float MonthlyPayment, float YearRate, float r, float YearTerm, float n)
{
printf("LOAN INFORMATION\n");
printf("-----------------------\n");
printf("Initial loan amount: %.2f\n", p);
printf("Annual interest rate: %.3f\n", YearRate);
printf("Monthly interest rate: %.3f\n", r);
printf("Term of loan (years): %f\n", YearTerm);
printf("Term of loan (months): %f\n", n);
printf("Monthly payment amount: %.2f\n", MonthlyPayment);
}
더 자세한 내용 *보다 * 구체적이어야합니다. '문제는 기능에있다'고 말하는 것은 '문제는 비행기 어딘가에있다'고 말하는 항공기 정비사와 조금 다릅니다. 프로그램이 작동하지 않는다고하면 무슨 뜻입니까? 그것은 컴파일에 실패합니까? 그렇다면 오류에 대한 세부 정보를 제공해야합니다. 그렇지 않은 경우 제공하는 입력 내용과 예상 출력 내용을 실제 출력과 함께 제공해야합니다. MVCE (http://stackoverflow.com/help/mcve) –
을 제공하십시오. 앞으로 프로그램의 의도 된 동작과 그 동작에 대해 설명하십시오. 컴파일에 실패하면 컴파일러에서 제공하는 오류 메시지를 알려주십시오.일단 당신이 그것을 찾기 시작하면 여기의 문제가 두드러지지 만, 항상 그런 것은 아닙니다. 코드를 실행하려고 할 때 다른 사람이 문제가 발생하더라도 문제가 발생했는지 여부를 확인할 방법이 없습니다. 감사. –