Join 137,402 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,114 people online right now. Registration is fast and FREE... Join Now!
I want to know if I'm using funcations correctlry to run this program. I also wanted to know if I should use an arry to pass the information from one funcation to the nect
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); {
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
the function definations and prototypes here are incorrect. first of all you are defining the functions in another function main () which is not allowed. next the return data types in function prototypes and definations of calculate() and amortization() dont match .in the prototype of calculate() the argument list is incorrect . for the definations of amortization() you are not specifying the arguments whaich are to be passed to it i.e is void in this case. next all three functions dont have a return data type and all the function headers in the definations have a semi colon at there end . that shud be removed
i need help. I have the program written with no code. But I'm having an issue getting to the functions . Need some help please
CODE
#include <stdio.h> #include <math.h>
double CollectInput (double LoanAmount, int TermLoan, double InterestRate, int c); double Calculate (int n, double a, double i) ; double Amortization(double a, double InterestRate, double LoanBlance, double PaymentNumber, double AmountPrinciple, double AmountInterest, int InterestRate); 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
printf ("hit enter to end"); getchar (); getchar (); return 0; }
//**************************************************************** //Start of the function to collect data //**************************************************************** double CollectInput (double LoanAmount, int TermLoan, double InterestRate, int c, double i, double n, double CurrentBlance,double Numberofmonths, double a, double PaymentNumber, int count) {
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 //************************************************************* double Calculate (int n, double a, double i, double PaymentAmout, double PaymentNumber, int Numberofmonths, double PaymentAmount, int count, double AmountInterest, double AmountPrinciple, double LoanBlance ) {
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
Please elaborate on the problem you are encountering.
All that i get is please hit enter. it dose not take me to my funcations. It dose not allow me to eneter in the data and then pass it to the next funcation.
Not specifically (although there are a couple of small issues - each of your functions has a return type, but you are not returning any values, for example)...what I'm saying is that you have written several functions, but you are not calling them from your main function. Think of it like a taxi...you know it exists, but you are currently waiting for it to show up and transport you, despite the fact you have not informed the taxi that you are waiting.
You actually need to call the functions themselves.
Do you want the function to return a value? If so, what data type do you want it to return?
ok like the frist funcation. I need it to pass to the second funcation to do the calcauation i = InterestRate/ 100; n = Numberofmonths; a = CurrentBlance; PaymentNumber = 0; count = 0;
The second funcation i need to pass to the thier to print. 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);
I think i need a loop or an arry to print out all of the data. Let me know if I'm on the correct path.