473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Issues with a program

In the program below i need to get it, so that it will keep going through the program asks all the question and displays the results and goes back to the beginning if the user didn't select. After displaying the results, return to the menu to let the user choose another formula or exit.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. #include <iomanip>
  5. #include <cctype>
  6. #include <cmath>
  7.  
  8. double func1(double factor, double monthly_interest, double loan_amount);
  9. double func2(double factor, double monthly_payment, double monthly_interest);
  10. double func3(double factor, double monthly_amount, double monthly_interest);
  11. double func4(double total, double monthly_interest, double factor);
  12. double func5(double monthly_interest, double number_months, double years);
  13. double func6(double interest_rate, double years);
  14. void func7(double loan_amount, double years, double interest_rate, double monthly_payment);
  15. void func8(double total, double years, double interest_rate, double monthly_amount);
  16.  
  17. int main()
  18. {
  19.  
  20.     double interest_rate, number_months, monthly_payment, loan_amount, total;
  21.     int calc_number;
  22.     double years = 0, monthly_amount, factor, monthly_interest;
  23.  
  24.     cout << "1 - Compute a Loan Payment for a given Loan Amount to be borrowed." << endl;
  25.     cout << "2 - Compute the Loan Amount you could borrow for a given affordable" << endl;
  26.     cout << "    Monthly Payment." << endl;
  27.     cout << "3 - Compute the Total amount that will be accumulated for a given" << endl;
  28.     cout << "    Monthly Amount saved." << endl;
  29.     cout << "4 - Compute Monthly Amount required to accumulate a given Total amount." << endl;
  30.     cout << "5 - Exit the program." << endl << endl;
  31.     cout << "Please Choose a number to perform the following calculations: ";
  32.     cin >> calc_number;
  33.     cout << endl;
  34.  
  35.     cout << "What is the annual interest rate? ";
  36.     cin >> interest_rate;
  37.     cout << endl;
  38.     cout << "What is the number of years to borrow or save? ";
  39.     cin >> years;
  40.     cout << endl;
  41.  
  42.   monthly_interest = func6(interest_rate, years);
  43.   factor = func5(monthly_interest, number_months, years);
  44.  
  45.  
  46.   switch(calc_number)
  47.     {
  48.          case 1:
  49.               cout << "What is the Loan Amount?  ";
  50.               cin >> loan_amount;
  51.               cout << endl;
  52.               monthly_payment = func1(factor, monthly_interest, loan_amount);
  53.               func7(loan_amount, years, interest_rate, monthly_payment);
  54.               break;
  55.  
  56.          case 2:
  57.               cout << "What is the given affordable Monthly Payment?  ";
  58.               cin >> monthly_payment;
  59.               cout << endl;
  60.               loan_amount = func2(factor, monthly_payment, monthly_interest);
  61.               func7(loan_amount, years, interest_rate, monthly_payment);
  62.               break;
  63.  
  64.          case 3:
  65.               cout << "What is the Monthly Amount saved?  ";
  66.               cin >> monthly_amount;
  67.               cout << endl;
  68.               total = func3(factor, monthly_amount, monthly_interest);
  69.               func8(total, years, interest_rate, monthly_amount);
  70.               break;
  71.  
  72.          case 4:
  73.               cout << "What is the Total amount?  ";
  74.               cin >> total;
  75.               cout << endl;
  76.               monthly_amount = func4(total, monthly_interest, factor);
  77.               func8(total, years, interest_rate, monthly_amount);
  78.               break;
  79.  
  80.          case 5:
  81.               cout <<"You have chosen to exit the program" << endl;
  82.               cout <<"Good-bye!"<< endl;
  83.               cout << endl << endl;                                                        
  84.               system("PAUSE");                                                            
  85.               return EXIT_SUCCESS; 
  86.     }      
  87.  
  88.     cout << endl << endl;                                                       
  89.     system("PAUSE");                                                            
  90.     return EXIT_SUCCESS;  
  91.  
  92. }
  93.  
  94. void func7(double loan_amount, double years, double interest_rate, double monthly_payment)
  95. {
  96.     cout <<  setw(34) << "Annual" << endl;
  97.     cout << "Loan" << setw(16) << "Number" << setw(16) << "Interest";
  98.     cout << setw(10) << "Monthly" << endl;
  99.     cout << "Amount" << setw(16) << "of Years" << setw(10) << "Rate";
  100.     cout << setw(14) << "Payment" << endl;
  101.     cout << "-----------  " << setw(3) << " -----------  ";
  102.     cout << " --------  " << setw(3) << " ---------" << endl;
  103.     cout << fixed << showpoint << setprecision(2);
  104.     cout <<"$" << setw(2) << loan_amount;
  105.     cout << fixed << noshowpoint << setprecision(0);
  106.     cout << setw(8) << years << " years";
  107.     cout << fixed << showpoint << setprecision(1);
  108.     cout << setw(10) << interest_rate << "%" << setw(8) << "$";
  109.     cout << fixed << showpoint << setprecision(2);
  110.     cout << setw(2) << monthly_payment << endl;
  111. }
  112.  
  113.  
  114. void func8(double total, double years, double interest_rate, double monthly_amount)
  115. {
  116.     cout << "Total" << setw(29) << "Annual" << setw(12) << "Monthly" << endl;
  117.     cout << "Amount" << setw(14) << "Number" << setw(16) << "Interest";
  118.     cout << setw(10) << "Savings" << endl;
  119.     cout << "Saved" << setw(17) << "of Years" << setw(10) << "Rate";
  120.     cout << setw(15) << "Required" << endl;
  121.     cout << "-----------  " << setw(3) << " -----------  ";
  122.     cout << " --------  " << setw(3) << " ---------" << endl;
  123.     cout << fixed << showpoint << setprecision(2);
  124.     cout <<"$" << setw(2) << total;
  125.     cout << fixed << noshowpoint << setprecision(0);
  126.     cout << setw(6) << years << " years";
  127.     cout << fixed << showpoint << setprecision(1);
  128.     cout << setw(10) << interest_rate << "%" << setw(8) << "$";
  129.     cout << fixed << showpoint << setprecision(2);
  130.     cout << setw(2) << monthly_amount << endl;
  131.  
  132.  
  133. double func6(double interest_rate, double years)
  134. {
  135.  
  136.     return((interest_rate / 100) / 12);
  137. }
  138.  
  139. double func5(double monthly_interest, double number_months, double years)
  140. {
  141.     number_months = years * 12;
  142.     return((exp(number_months * log(1 + monthly_interest))));
  143. }
  144.  
  145. double func4(double total, double monthly_interest, double factor)
  146. {
  147.     return((total * monthly_interest) / (factor - 1));
  148. }
  149.  
  150. double func3(double factor, double monthly_amount, double monthly_interest)
  151. {
  152.     return((((factor - 1) * monthly_amount) / monthly_interest));
  153. }   
  154.  
  155. double func2(double factor, double monthly_payment, double monthly_interest)
  156. {
  157.     return(((factor - 1) * monthly_payment) / (factor * monthly_interest));
  158. }
  159.  
  160. double func1(double factor, double monthly_interest, double loan_amount)
  161. {
  162.     return((factor * monthly_interest * loan_amount) / (factor - 1));
  163. }
  164.  
  165.  
Dec 16 '06 #1
1 2872
Expand|Select|Wrap|Line Numbers
  1.  
  2. while(1)
  3. {
  4.    /*menu and questions*/
  5.  
  6.    /*switch case*/
  7.  
  8.    case 5:
  9.    /*Add following line*/
  10.    exit(0);
  11. }
  12.  
  13.  
Dec 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Phil IU Guy | last post by:
I am having 2 issues, both acting very randomly, and for the most part I dont get this message on most computers, but I have had a couple computers get either issue 1, or issue 2. Issue #1: I...
4
by: Martin | last post by:
I am using graphics as backgrounds for forms,buttons,labels etc. The question is: is it faster to load all graphics from files on app start or to use it embeded (places in editor during design)....
1
by: J | last post by:
I am having issues with a VBA in a rockwell program called RSView SE. (Industral touch panel software.) I know that most of you ppls dont deal with this program, but I was hoping you might be...
8
by: GaryDean | last post by:
In an 2.0 asp app I used vs.net 2005 to create a TableAdapter:Dataset in my App_code directory. I also created a new vb class in that same directory. I have two issues: 1. I notice that there...
2
by: et | last post by:
In my asp.net 1 program, I have a business layer, which lays out all my business rules, and of course communicates with the data layer, which accesses a sql database and returns data. No problems....
4
by: Bucco | last post by:
I installed python 2.5b3 on my windows XP sp2 box without any issues. I can double click the python program, and idle comes up in the command line window. However when I run python from the...
4
by: Viviana Vc | last post by:
Hi all, I've read the WindowsVistaUACDevReqs.doc documentation and I have done different small tests on Vista to understand the bahaviour and now I have a few questions. 1) If I create a...
4
by: mrjaxon | last post by:
I have a C# web application which leverages MSXML that I am trying to migrate to a 64 bit environment. Currently the application is built on the .NET 2.0 Framework and using MSXML 6 (though I had...
14
by: Stephany Young | last post by:
Even though I had my roots and highlights redone just a few days ago, I don't understand why I appear to be having an ongoing blond moment. Is it just me or do others among you not 'get' how to...
5
by: Alexnb | last post by:
Hello I am sure most of you are familiar with py2exe. I am having a bit of a problem. See the program has a few pictures involved and the .ico it uses for the windows. However, the pictures are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.