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
}

Deleted post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.