User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Mar 2004
Posts: 12
Reputation: popo_prince is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
popo_prince popo_prince is offline Offline
Newbie Poster

program help

  #1  
May 17th, 2004
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
} 
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,647
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 144
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: program help

  #2  
May 17th, 2004
Deleted post.
Last edited by The Other Dave : May 17th, 2004 at 10:28 pm. Reason: Deleted
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC