program help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2004
Posts: 12
Reputation: popo_prince is an unknown quantity at this point 
Solved Threads: 0
popo_prince popo_prince is offline Offline
Newbie Poster

program help

 
1
  #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.

  1. #include <iostream.h>
  2. double MonthlyPayment (double amount, double rate, int months);
  3. int GetChoice(void);
  4.  
  5. int main( );
  6.  
  7. //struct Choice
  8. static const Choice menu[] = ( 7, 5.35, 15, 5.5, 30, 5.75 ); //if i put the colon before menu= lots of errors
  9. {
  10. int term;
  11. double rate;
  12. void Show()
  13. {
  14. std::cout << term << " years @ " << rate << '%' << std::endl;
  15. }
  16. };
  17.  
  18. int main();
  19. {
  20.  
  21. size_t selection;
  22. do
  23. {
  24. for ( size_t i = 0; i < sizeof menu / sizeof *menu; ++i )
  25. {
  26. std::cout << '(' << i << ") ";
  27. menu[i].Show();
  28. }
  29. std::cout << "Selection ? ";
  30. std::cin >> selection;
  31. } while ( selection >= sizeof menu / sizeof *menu );
  32. std::cout << "Your selection:\n";
  33. menu[selection].Show();
  34. return 0;
  35. }
  36. {
  37.  
  38. double months, amount, rate;
  39. int option;
  40.  
  41. //create a loop
  42. while((option = GetChoice()) == 1)
  43. {
  44. //option = GetChoice();
  45. cout << "Enter the loan amount: ";
  46. cin >> amount;
  47. cout << "Enter the interest rate (X.Y): ";
  48. cin >> rate;
  49. cout << "Enter the length of the loan in months : ";
  50. cin >> months;
  51. //this line will generate a loss of data warning
  52. cout << "\tYour monthly payment is $ "<<MonthlyPayment(amount, rate, months)<<endl;
  53.  
  54. }
  55. return 0;
  56. }
  57.  
  58. int GetChoice(void)
  59. {
  60. int num;
  61. cout << endl;
  62. cout << "1. Calculate your monthly payment on the loan."
  63. << endl << "You will enter the loan amount, Interest rate, and Length of the loan" << endl;
  64. cout << "0. Exit the program" << endl;
  65. cout << "Press 1 to procede : ";
  66. cin >> num;
  67. return num;
  68. }
  69.  
  70. double MonthlyPayment (double amount, double rate, int months)
  71. {
  72. //declare a local variable to be used for calc's and to hold return value, not function name!
  73. double monthPayment;
  74. // do the calc's
  75. //amount, months and rates values declared in prototype parameters, no need to define local variables
  76. monthPayment = (amount * months) / rate /1200;
  77.  
  78. return monthPayment; //return the double
  79. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: program help

 
0
  #2
May 17th, 2004
Deleted post.
Last edited by The Other Dave; May 17th, 2004 at 11:28 pm. Reason: Deleted
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC