943,469 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3003
  • C++ RSS
May 17th, 2004
1

program help

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
popo_prince is offline Offline
12 posts
since Mar 2004
May 17th, 2004
0

Re: program help

Deleted post.
Last edited by The Other Dave; May 17th, 2004 at 11:28 pm. Reason: Deleted
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Visual C++
Next Thread in C++ Forum Timeline: Cd-drive





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC