By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

need help with Funcation all around

P: 1
I have done this . Write a C program that will accept keyboard
input and display a loan amortization schedule back on the screen. The
program should ask for the Loan Amount (real number), Term of the Loan
in months (integer), and the Interest Rate (real number); the input data
should be validity checked. The output should list a heading showing the
input values, then a separate line indicating Payment Number, Loan
Balance, Payment Amount, Amount to Principle, Amount to Interest, New
Balance for each payment. A loop should be used to display the
amortization list. The payment amount is calculated using the formula:
[ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n 1 ]
where i=interest rate, n=number of months, a=current balance
After completing one occurrence the program should exit.
and took it and modified to do 2. Due by the end of week 4. Modify the C program from assignment 1 to use function calls and pass parameters. The following functions should be used:
Collect Input (collect and validate input values),
Calculate a Payment, and
Write Amortization Line
i'm having issues to get my main program to read my funcation. I know that I'm missing the statement to call them in. But I also know that i have to may items to send out data from one funcation to the next. This is done all online so I do not have a teacher or anyone to ask question to. I need some help. I seem to have hit a brick wall and it keeps grow up and up.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. double CollectInput (double a, double i, int n, int Numberofmonths,  int PaymentNumber, int count);
  6. double Calculate (int n,double a, double i,double PaymentAmount,double PaymentNumber, 
  7.          double Numberofmonths, int count, double AmountInterest, 
  8.          double AmountPrinciple, double LoanBlance); 
  9. double Amortization (double a, double InterestRate, double LoanAmount, int PaymentNumber, 
  10.              double AmountPrinciple, double AmountInterest, double LoanBlance, double PaymentAmount); 
  11.  
  12.  
  13. main ()
  14. {
  15.  
  16. int   TermLoan,  // length of the loan
  17.          PaymentNumber,  //number of payments made
  18.           Numberofmonths, //Number of months in the loan
  19.           count,
  20.           n,c; //Letters used for the calculations
  21. double   AmountPrinciple, //Amount paid on principle
  22.          AmountInterest,  //amount paid to interest
  23.          LoanBlance, //amount owed on loan\ count,
  24.          CurrentBlance,
  25.           LoanAmount, //amount of the loan  
  26.          InterestRate, //interest rate on loan
  27.           returnedValue,  a,i,
  28.            PaymentAmount;  //amount paid to loan 
  29.  
  30.  
  31.   CollectInput  (a, i, n, Numberofmonths, PaymentNumber, count);
  32.   returnedValue = CollectInput (a, i, n, Numberofmonths, PaymentNumber, count);
  33.   Calculate (n, a, i, PaymentAmount, PaymentNumber, Numberofmonths, count, 
  34.             AmountInterest, AmountPrinciple, LoanBlance );
  35.  
  36.  
  37.    Amortization (a, InterestRate, LoanAmount, PaymentNumber, AmountPrinciple, 
  38.                  AmountInterest, LoanBlance, PaymentAmount);                         
  39.  
  40.  
  41.  
  42. printf ("hit enter to end");
  43. getchar ();
  44. getchar ();
  45. return 0;         
  46. }
  47.  
  48. //****************************************************************      
  49. //Start of the function to collect data
  50. //****************************************************************
  51. double CollectInput (double a, double i, int n, int Numberofmonths, int PaymentNumber, int count)
  52.      {
  53.       int TermLoan,
  54.            c ;
  55.       double LoanAmount,
  56.              InterestRate,
  57.              CurrentBlance;
  58.  
  59.         while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
  60.                      || (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
  61.           {
  62.              while ((c = getchar()) != '\n' && c != EOF);
  63.              printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n");
  64.              }
  65.  
  66.  
  67.              CurrentBlance = LoanAmount;
  68.                Numberofmonths = TermLoan; 
  69.                i = InterestRate/ 100;    
  70.                n = Numberofmonths;
  71.                a = CurrentBlance;
  72.                 PaymentNumber = 0;
  73.                 count = 0; 
  74.  
  75.                 return i, n, a, PaymentNumber, count; 
  76.    }  //end of collect data
  77.  
  78.  
  79. //********************************************************************
  80. //Start of Calculate function
  81. //*************************************************************
  82.  double Calculate (int n,double a, double i,double PaymentAmount,double PaymentNumber, 
  83.          double Numberofmonths, int count, double AmountInterest, 
  84.          double AmountPrinciple, double LoanBlance)              
  85.    {
  86.  
  87.  
  88.          PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
  89.  
  90.             while(PaymentNumber < Numberofmonths)
  91.              {
  92.  
  93.              PaymentNumber++; //Start number of months for amortization schedule
  94.              count++;
  95.              AmountInterest = a  * (i/12);  
  96.              AmountPrinciple = PaymentAmount - AmountInterest;
  97.              LoanBlance = a - AmountPrinciple;
  98.              a = LoanBlance; 
  99.              return a, PaymentNumber, LoanBlance, PaymentAmount, 
  100.                    AmountPrinciple, AmountInterest; 
  101.                 }//end of while loop 
  102.    } //end of Calculate Function
  103.  
  104.  
  105. //*********************************************************************
  106. //State of print function
  107. //************************************************************
  108. double Amortization (double a, double InterestRate, double LoanAmount,  int PaymentNumber, 
  109.         double AmountPrinciple, double AmountInterest, double LoanBlance, double PaymentAmount)
  110. {
  111.           printf ("\amortization Schedule\n");
  112.             printf ("_____________________\n");
  113.            printf ("CurrentBlance %.2f\n", a);
  114.            printf ("InterestRate %.2f\n", InterestRate); 
  115.           printf ("PaymentNumber %d\n",  PaymentNumber);
  116.           printf ("LoanBlance  %.2f\n", LoanBlance);
  117.           printf ("PaymentAmount %.2f\n", PaymentAmount);
  118.           printf ("AmountPrinciple %.2f\n", AmountPrinciple);
  119.           printf  ("AmountInterest %.2f\n", AmountInterest);
  120.           printf ("_______________________\n\n");
  121.  
  122.           return 0;
  123. } //end of Amortization print function
  124.  
  125.  
  126.  
  127.  
Sep 20 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.