Code:
#include "amort.h"
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include<ctype.h>
#include<conio.h>
//extern double getPaymentAmount(double principal,int numberOfMonths,double interest);
//extern double getLoanAmount(double payment,int numberOfMonths,double interest);
//extern int getNumberOfMonths(double payment, double principal,double interest);
int main(void)
{
int choice;
int numberOfMonths;
int months;
float interest;
double principal;
double payment;
do
{
system("cls");
printf("Welcome to Amortization Calculator by Yongho Kim\n");
printf("==========================================\n");
printf("1.calculate size of payments\n");
printf("2.calculate size of the loan\n");
printf("3.calculate number of payments\n");
printf("4.exit\n");
printf("==========================================\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter annual interest rate: ");
scanf("%f",&interest);
while(interest<=0)
{
printf("annual interest rate should be >0: ");
scanf("%f",&interest);
}
printf("\nInterest rate: %.2f\n",interest);
printf("Enter principal amount: ");
scanf("%lf",&principal);
printf("\nPrincipal amount:$ %.2f\n",principal);
printf("Enter number of months: ");
scanf("%d",&numberOfMonths);
printf("\nNumber of months: %d\n",numberOfMonths);
payment = getPaymentAmount(interest,numberOfMonths,principal/1200);
printf("Payment Amount=$ %.2lf",payment);
break;
case 2:
printf("Enter annual interest rate: ");
scanf("%lf",&interest);
while(interest<=0)
{
printf("annual interest rate should be >0: ");
scanf("%lf",&interest);
}
printf("\nInterest rate:$ %.2f\n",interest);
printf("Enter payment amount: ");
scanf("%lf",&payment);
printf("\nPayment amount:$ %.2f\n",payment);
printf("Enter number of months: ");
scanf("%d",&numberOfMonths);
printf("\nNumber of months: %d\n",numberOfMonths);
principal = getLoanAmount(payment,numberOfMonths,interest/1200);
printf("Principal Amount=$ %.2lf",principal);
break;
case 3:
printf("Enter annual interest rate: ");
scanf("%lf",&interest);
while(interest<=0)
{
printf("annual interest rate should be >0: ");
scanf("%lf",&interest);
}
printf("\nInterest rate:$ %.2f\n",interest);
printf("Enter principal amount: ");
scanf("%lf",&principal);
printf("\nPrincipal amount:$ %.2f\n",principal);
printf("Enter payment amount: ");
scanf("%d",&payment);
printf("\nPayment amount:$ %.2f\n",payment);
months = getNumberOfMonths(payment,principal,interest/1200);
printf("NUmber of months= %d",months);
break;
case 4:
return 1;
}
printf("\n\n\n\nWould you like to start over? Y/N");
}while( getch() == 'y' || getch() == 'Y');
return 1;
}
=====================
#include "amort.h"
#include <math.h>
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
double getPaymentAmount(double interest, int numberOfMonths, double principal)
{
double numerator,denominator;
numerator= powf((1+interest),numberOfMonths)*principal*interest;
denominator=powf((1+interest),numberOfMonths)-1;
return numerator/denominator;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
double getLoanAmount(double interest, int numberOfMonths, double payment)
{
double numerator,denominator;
numerator=powf((1+interest),numberOfMonths) - 1*payment;
denominator=interest*powf((1+interest),numberOfMonths);
return numerator/denominator;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
int getNumberOfMonths(double interest, double payment, double principal)
{
double numerator,denominator;
numerator=log(payment)-log(payment-(principal*interest));
denominator=log(1+interest);
return numerator/denominator;
}
===============
#ifndef AMORT_H
#define AMORT_H
#include <math.h>
#pragma once
double getPaymentAmount(double principal,int numberOfMonths,double interest);
double getLoanAmount(double payment,int numberOfMonths,double interest);
int getNumberOfMonths(double payment, double principal,double interest);
#endif
the output that im suppose to get isnt right... it keeps giving me random numbers or too high. can someone help me with this??