| | |
how to call this function...using menu..!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
hello there..! can somebody help me how to call this function...the program function will appear when i select the case no 3 at swich code... however there is an error appear...bytheway is it correct i using "void loan_schedule ();"..to Generate loan payment schedule coding...when i choose number 3 at main menu...
#include <math.h> // pow()
#include <iostream.h>
#include <iomanip.h> // setprecision(), setw()
///////////////////////////////////////////
int show_menu();
void loan_schedule ();
///////////////////////////////////////////////////////////////
int show_menu()
{
int answer;
void ProcessInterestAmount();
cls();
cout<<endl<<endl;
cout<<"\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t% A'LONG CAR LOAN FEATURES %" <<endl;
cout<<"\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl<<endl;
cout << "What kind of value do you want to estimate?";
cout << "\n1 - Calculate the monthly installment";
cout << "\n2 - To take loanEstimate the interest rate applied on a loan";
cout << "\n3 - To build laon schedule";
cout << "\n4 - Estimate the interest rate applied on a loan";
cout<<"\n5 - EXIT"<<endl<<endl;
cout<<"\t\tCHOOSE YOUR SELECTION :";
cin >> answer;
switch(answer)
{
case 1:
{ monthlyinstallament();
break;}
case 2:
{ totakeloan();
break;}
case 3:
{ loan_schedule();
break;}/*
case 4:
ProcessPrincipal();
break;
case 5:
ProcessPeriod();
break;*/
default:
cout << "\nInvalid Selection\n";
}
getch ();
return 0;
}
/////////////////////////////////////////////////////////
// Generate loan payment schedule
void loan_schedule(double principal,double interest_rate,double term_years,double compounding_periods_per_year);
int main(int argc,char *argv[])
{
double inprincipal, inrate, interms;
if (argc > 1)
inprincipal = atof(argv[1]);
else {
cout << endl << "Amount of loan
";
cin >> inprincipal;
}
if ( inprincipal< 0.005) {
cout << "Bad loan amount!" << endl;
return 1;
}
if (argc > 2)
inrate = atof(argv[2]);
else {
cout << "Annual interest rate(%):";
cin >> inrate;
}
if ( inrate < 1) inrate *= 100;
if ( inrate< 1) {
cout << "Bad interest rate!" << endl;
return 1;
}
if (argc > 3)
interms = atof(argv[3]);
else {
cout << "Number of years:";
cin >> interms;
}
if ( interms< 0.005) {
cout << "Bad number of years!" << endl;
return 1;
}
loan_schedule( inprincipal, inrate, interms, 12);
return 0;
}
void loan_schedule(double principal,double interest_rate,double term_years,double compounding_periods_per_year)
{
double irate; // interest rate
double term; // number of compounding periods for life of loan
double paymt; // payment per compounding period.
int paymentnum; // number of payments
double balance; // running remaining principal to be paid
double totalpayment; // accumulated payments
double totalipaid; // accumulated interest paid
double totalppaid; // accumulated principal paid
// Generate header
cout << endl;
cout << "Loan Payback Schedule" << endl;
cout << "on $" << setprecision(2) << principal ;
cout << " at " << interest_rate << "%" ;
cout << " annually for " << term_years << " year(s)" << endl ;
if (fabs(compounding_periods_per_year - 1) > 0.0001) {
cout << "compounded " << compounding_periods_per_year;
cout << " times per year" << endl;
}
cout << endl;
cout << "PAYMENT # ";
cout << "BALANCE ";
cout << "PAYMENT ";
cout << "INTEREST PAID ";
cout << "PRINCIPAL PAID ";
cout << "REMAINING";
cout << endl << endl;
// Initialize variables for loop
irate = interest_rate/(100*compounding_periods_per_year);
term = term_years*compounding_periods_per_year;
paymt = ceil(100*principal*irate*pow(1+irate,term)
/(pow(1+irate,term)-1))
/100;
paymentnum = 0;
balance = principal;
totalpayment = 0;
totalipaid = 0;
totalppaid = 0;
cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);
// Report each period's payment
while (balance>0.005) { // need to pay if more 1/2 cent outstanding
cout << setw(9) << ++paymentnum;
cout << setw(9) << balance;
if (paymt > balance*(1+irate))
paymt = ceil(100*balance*(1+irate)-0.5)/100;
cout << setw(9) << paymt;
totalpayment += paymt;
cout << setw(15) << balance*irate ;
totalipaid += balance*irate;
cout << setw(16) << (paymt-balance*irate);
totalppaid += paymt - balance*irate;
balance -= paymt - balance*irate;
cout << setw(11) << balance;
cout << endl;
}
// Summarize loan payments
cout << endl;
cout << "Total payments: " << paymentnum << endl;
cout << "Total paid: $" << setw(14) << totalpayment << endl;
cout << "Interest paid: $" << setw(14) << totalipaid << endl;
cout << "Principal paid: $" << setw(14) << totalppaid << endl;
}
error
C:\mydocuments.cpp(293) : error C2731: 'main' : function cannot be overloaded
#include <math.h> // pow()
#include <iostream.h>
#include <iomanip.h> // setprecision(), setw()
///////////////////////////////////////////
int show_menu();
void loan_schedule ();
///////////////////////////////////////////////////////////////
int show_menu()
{
int answer;
void ProcessInterestAmount();
cls();
cout<<endl<<endl;
cout<<"\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t% A'LONG CAR LOAN FEATURES %" <<endl;
cout<<"\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl<<endl;
cout << "What kind of value do you want to estimate?";
cout << "\n1 - Calculate the monthly installment";
cout << "\n2 - To take loanEstimate the interest rate applied on a loan";
cout << "\n3 - To build laon schedule";
cout << "\n4 - Estimate the interest rate applied on a loan";
cout<<"\n5 - EXIT"<<endl<<endl;
cout<<"\t\tCHOOSE YOUR SELECTION :";
cin >> answer;
switch(answer)
{
case 1:
{ monthlyinstallament();
break;}
case 2:
{ totakeloan();
break;}
case 3:
{ loan_schedule();
break;}/*
case 4:
ProcessPrincipal();
break;
case 5:
ProcessPeriod();
break;*/
default:
cout << "\nInvalid Selection\n";
}
getch ();
return 0;
}
/////////////////////////////////////////////////////////
// Generate loan payment schedule
void loan_schedule(double principal,double interest_rate,double term_years,double compounding_periods_per_year);
int main(int argc,char *argv[])
{
double inprincipal, inrate, interms;
if (argc > 1)
inprincipal = atof(argv[1]);
else {
cout << endl << "Amount of loan
";cin >> inprincipal;
}
if ( inprincipal< 0.005) {
cout << "Bad loan amount!" << endl;
return 1;
}
if (argc > 2)
inrate = atof(argv[2]);
else {
cout << "Annual interest rate(%):";
cin >> inrate;
}
if ( inrate < 1) inrate *= 100;
if ( inrate< 1) {
cout << "Bad interest rate!" << endl;
return 1;
}
if (argc > 3)
interms = atof(argv[3]);
else {
cout << "Number of years:";
cin >> interms;
}
if ( interms< 0.005) {
cout << "Bad number of years!" << endl;
return 1;
}
loan_schedule( inprincipal, inrate, interms, 12);
return 0;
}
void loan_schedule(double principal,double interest_rate,double term_years,double compounding_periods_per_year)
{
double irate; // interest rate
double term; // number of compounding periods for life of loan
double paymt; // payment per compounding period.
int paymentnum; // number of payments
double balance; // running remaining principal to be paid
double totalpayment; // accumulated payments
double totalipaid; // accumulated interest paid
double totalppaid; // accumulated principal paid
// Generate header
cout << endl;
cout << "Loan Payback Schedule" << endl;
cout << "on $" << setprecision(2) << principal ;
cout << " at " << interest_rate << "%" ;
cout << " annually for " << term_years << " year(s)" << endl ;
if (fabs(compounding_periods_per_year - 1) > 0.0001) {
cout << "compounded " << compounding_periods_per_year;
cout << " times per year" << endl;
}
cout << endl;
cout << "PAYMENT # ";
cout << "BALANCE ";
cout << "PAYMENT ";
cout << "INTEREST PAID ";
cout << "PRINCIPAL PAID ";
cout << "REMAINING";
cout << endl << endl;
// Initialize variables for loop
irate = interest_rate/(100*compounding_periods_per_year);
term = term_years*compounding_periods_per_year;
paymt = ceil(100*principal*irate*pow(1+irate,term)
/(pow(1+irate,term)-1))
/100;
paymentnum = 0;
balance = principal;
totalpayment = 0;
totalipaid = 0;
totalppaid = 0;
cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);
// Report each period's payment
while (balance>0.005) { // need to pay if more 1/2 cent outstanding
cout << setw(9) << ++paymentnum;
cout << setw(9) << balance;
if (paymt > balance*(1+irate))
paymt = ceil(100*balance*(1+irate)-0.5)/100;
cout << setw(9) << paymt;
totalpayment += paymt;
cout << setw(15) << balance*irate ;
totalipaid += balance*irate;
cout << setw(16) << (paymt-balance*irate);
totalppaid += paymt - balance*irate;
balance -= paymt - balance*irate;
cout << setw(11) << balance;
cout << endl;
}
// Summarize loan payments
cout << endl;
cout << "Total payments: " << paymentnum << endl;
cout << "Total paid: $" << setw(14) << totalpayment << endl;
cout << "Interest paid: $" << setw(14) << totalipaid << endl;
cout << "Principal paid: $" << setw(14) << totalppaid << endl;
}
error
C:\mydocuments.cpp(293) : error C2731: 'main' : function cannot be overloaded
•
•
Join Date: Sep 2004
Posts: 56
Reputation:
Solved Threads: 2
Your function loan_schedule is written wrong. The function header requires parameters. While your function call and prototype have no parameters. I'm surprised it even compiles.
Future note also. If you post again put the code in bb tags and in a much more easy on the eyes form. Dont have two to four blank lines between similiar pieces of code.
Future note also. If you post again put the code in bb tags and in a much more easy on the eyes form. Dont have two to four blank lines between similiar pieces of code.
![]() |
Similar Threads
- How to call a function named in a string? (Python)
- Warning: Unknown(): Unable to call () - function does not exist in Unknown on line 0 (PHP)
- how to call a function in href? (ASP.NET)
- Call Function (ASP.NET)
- Using a for loop to sum an integer n and call function add_it (C)
Other Threads in the C++ Forum
- Previous Thread: urgent..i need help..
- Next Thread: i don't know how to start
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





