Hey everyone!
I'm new to programming (taking a class in C) and have two errors I don't know how to fix.
The errors are:
try1.c:17: error: conflicting types for calculateMonthlyPayment
try1.c:12: error: previous implicit declaration of calculateMonthlyPayment was here
I know they're related, but can't figure out how to correct them. Help?
Program:
Code:
#include <stdio.h>
#include <math.h>
double calculateMontlyPayment (double amount, double rate, double years);
void printInformation (double amount, double rate, double years, double calculate);
int main ()
{
double rate, amount, years, calculate;
printf ("Enter the loan amount, interest rate (as a percent), and number of years for the loan\n\n");
scanf ("%lf%lf%lf", &amount, &rate, &years);
calculate=calculateMonthlyPayment (amount, rate, years);
printInformation (amount, rate, years, calculate);
return 0;
}
double calculateMonthlyPayment (double amount, double rate, double years)
{
return ((rate*pow((1.0+rate), (years*12.0)))/(pow((1.0+rate), (years*12.0))-1.0)*amount);
}
void printInformation (double amount, double rate, double years, double calculate)
{
printf ("The amount of the loan: %6.2lf\n", amount);
printf ("Interest rate per year (user entered): %6.2lf\n", rate);
printf ("Interest rate per month: \n");
printf ("Number of years: %6.2lf\n", years);
printf ("Number of months: %6.2lf\n", (years*12));
printf ("Monthly payment: %6.2lf\n", calculate);
}