•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,495 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,456 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1960 | Replies: 1
![]() |
•
•
Join Date: Mar 2004
Posts: 12
Reputation:
Rep Power: 5
Solved Threads: 0
i have been trying to incorporate various element into this mortgage calculation program. it is supposed to present the three options from the array or prompt you to enter your own rates. my structure with the public and private sections are out of place. i need help streamlining this and resolving its massive errors from my faulty logic.
#include <iostream.h>
double MonthlyPayment (double amount, double rate, int months);
int GetChoice(void);
int main( );
//struct Choice
static const Choice menu[] = ( 7, 5.35, 15, 5.5, 30, 5.75 ); //if i put the colon before menu= lots of errors
{
int term;
double rate;
void Show()
{
std::cout << term << " years @ " << rate << '%' << std::endl;
}
};
int main();
{
size_t selection;
do
{
for ( size_t i = 0; i < sizeof menu / sizeof *menu; ++i )
{
std::cout << '(' << i << ") ";
menu[i].Show();
}
std::cout << "Selection ? ";
std::cin >> selection;
} while ( selection >= sizeof menu / sizeof *menu );
std::cout << "Your selection:\n";
menu[selection].Show();
return 0;
}
{
double months, amount, rate;
int option;
//create a loop
while((option = GetChoice()) == 1)
{
//option = GetChoice();
cout << "Enter the loan amount: ";
cin >> amount;
cout << "Enter the interest rate (X.Y): ";
cin >> rate;
cout << "Enter the length of the loan in months : ";
cin >> months;
//this line will generate a loss of data warning
cout << "\tYour monthly payment is $ "<<MonthlyPayment(amount, rate, months)<<endl;
}
return 0;
}
int GetChoice(void)
{
int num;
cout << endl;
cout << "1. Calculate your monthly payment on the loan."
<< endl << "You will enter the loan amount, Interest rate, and Length of the loan" << endl;
cout << "0. Exit the program" << endl;
cout << "Press 1 to procede : ";
cin >> num;
return num;
}
double MonthlyPayment (double amount, double rate, int months)
{
//declare a local variable to be used for calc's and to hold return value, not function name!
double monthPayment;
// do the calc's
//amount, months and rates values declared in prototype parameters, no need to define local variables
monthPayment = (amount * months) / rate /1200;
return monthPayment; //return the double
} ![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science and Software Design)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP / 2003)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Visual C++
- Next Thread: Cd-drive



Linear Mode