functions and passing data
Im trying to take this code and modify it so that i have three funcations and pass data between the funcations. I have started to change the code and want to know if im on the right track,
Code:
/*************************************************************
File Name: Tmitchellwk2
Description: Display Loan Amortization Schedule via functions
Date: Spetembet 16, 2006
Designer; Tabatha Mitchell
Assignment: week2
Functions: int CollectInput; This will collect the input and validate Input values
int Calculate; this is where all of the calculations
Will be done
int Amortization: This is where all of the data
will be printed
**************************************************************/
#include <stdio.h>
#include <math.h>
double CollectInput (double LoanAmount, int TermLoan, double InerestRate);
double Calculate;
double Amortization;
main ()
{
int TermLoan, // length of the loan
PaymentNumber, //number of payments made
Numberofmonths, //Number of months in the loan
count,
n,c; //Letters used for the calculations
double AmountPrinciple, //Amount paid on principle
AmountInterest, //amount paid to interest
LoanBlance, //amount owed on loan\ count,
CurrentBlance,
LoanAmount, //amount of the loan
InterestRate, //interest rate on loan
a,i,
PaymentAmount; //amount paid to loan
/****************************************************************
//Start of the function to collect data
/****************************************************************
double CollectInput (double LoanAmount, int TermLoan, double InerestRate);
{
printf ("Please enter in loan amount, Term of Loan in months and Interest Rate.\n");
while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
|| (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
{
while ((c = getchar()) != '\n' && c != EOF);
printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n");
}
CurrentBlance = LoanAmount;
Numberofmonths = TermLoan;
i = InterestRate/ 100;
n = Numberofmonths;
a = CurrentBlance;
PaymentNumber = 0;
count = 0;
} //end of collect data
/********************************************************************
Start of Calculate function
/*************************************************************
int Calculate ( int n, double a, double i);
{
PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));
while(PaymentNumber < Numberofmonths)
{
PaymentNumber++; //Start number of months for amortization schedule
count++;
AmountInterest = a * (i/12);
AmountPrinciple = PaymentAmount - AmountInterest;
LoanBlance = a - AmountPrinciple;
a = LoanBlance;
}//end of while loop
} //end of Calculate Function
/**********************************************************************
State of print function
/*************************************************************
int Amortization;
{
printf ("\amortization Schedule\n");
printf ("_____________________\n");
printf ("CurrentBlance %.2f\n", a);
printf ("InterestRate %.2f\n", InterestRate);
printf ("PaymentNumber %d\n", PaymentNumber);
printf ("LoanBlance %.2f\n", LoanBlance);
printf ("PaymentAmount %.2f\n", PaymentAmount);
printf ("AmountPrinciple %.2f\n", AmountPrinciple);
printf ("AmountInterest %.2f\n", AmountInterest);
printf ("_______________________\n\n");
} //end of Amortization print function
printf ("hit enter to end");
getchar ();
getchar ();
return 0;
}