Issues with a program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • confusedprogrammer
    New Member
    • Sep 2006
    • 12

    #1

    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.

    Code:
    #include <iostream>
    using namespace std;
    #include <iomanip>
    #include <cctype>
    #include <cmath>
    
    double func1(double factor, double monthly_interest, double loan_amount);
    double func2(double factor, double monthly_payment, double monthly_interest);
    double func3(double factor, double monthly_amount, double monthly_interest);
    double func4(double total, double monthly_interest, double factor);
    double func5(double monthly_interest, double number_months, double years);
    double func6(double interest_rate, double years);
    void func7(double loan_amount, double years, double interest_rate, double monthly_payment);
    void func8(double total, double years, double interest_rate, double monthly_amount);
    
    int main()
    {
        
        double interest_rate, number_months, monthly_payment, loan_amount, total;
        int calc_number;
        double years = 0, monthly_amount, factor, monthly_interest;
        
        cout << "1 - Compute a Loan Payment for a given Loan Amount to be borrowed." << endl;
        cout << "2 - Compute the Loan Amount you could borrow for a given affordable" << endl;
        cout << "    Monthly Payment." << endl;
        cout << "3 - Compute the Total amount that will be accumulated for a given" << endl;
        cout << "    Monthly Amount saved." << endl;
        cout << "4 - Compute Monthly Amount required to accumulate a given Total amount." << endl;
        cout << "5 - Exit the program." << endl << endl;
        cout << "Please Choose a number to perform the following calculations: ";
        cin >> calc_number;
        cout << endl;
        
        cout << "What is the annual interest rate? ";
        cin >> interest_rate;
        cout << endl;
        cout << "What is the number of years to borrow or save? ";
        cin >> years;
        cout << endl;
       
      monthly_interest = func6(interest_rate, years);
      factor = func5(monthly_interest, number_months, years);
      
      
      switch(calc_number)
        {
             case 1:
                  cout << "What is the Loan Amount?  ";
                  cin >> loan_amount;
                  cout << endl;
                  monthly_payment = func1(factor, monthly_interest, loan_amount);
                  func7(loan_amount, years, interest_rate, monthly_payment);
                  break;
                  
             case 2:
                  cout << "What is the given affordable Monthly Payment?  ";
                  cin >> monthly_payment;
                  cout << endl;
                  loan_amount = func2(factor, monthly_payment, monthly_interest);
                  func7(loan_amount, years, interest_rate, monthly_payment);
                  break;
                  
             case 3:
                  cout << "What is the Monthly Amount saved?  ";
                  cin >> monthly_amount;
                  cout << endl;
                  total = func3(factor, monthly_amount, monthly_interest);
                  func8(total, years, interest_rate, monthly_amount);
                  break;
             
             case 4:
                  cout << "What is the Total amount?  ";
                  cin >> total;
                  cout << endl;
                  monthly_amount = func4(total, monthly_interest, factor);
                  func8(total, years, interest_rate, monthly_amount);
                  break;
                  
             case 5:
                  cout <<"You have chosen to exit the program" << endl;
                  cout <<"Good-bye!"<< endl;
                  cout << endl << endl;                                                        
                  system("PAUSE");                                                            
                  return EXIT_SUCCESS; 
        }      
        
        cout << endl << endl;                                                       
        system("PAUSE");                                                            
        return EXIT_SUCCESS;  
                                                            
    }
    
    void func7(double loan_amount, double years, double interest_rate, double monthly_payment)
    {
        cout <<  setw(34) << "Annual" << endl;
        cout << "Loan" << setw(16) << "Number" << setw(16) << "Interest";
        cout << setw(10) << "Monthly" << endl;
        cout << "Amount" << setw(16) << "of Years" << setw(10) << "Rate";
        cout << setw(14) << "Payment" << endl;
        cout << "-----------  " << setw(3) << " -----------  ";
        cout << " --------  " << setw(3) << " ---------" << endl;
        cout << fixed << showpoint << setprecision(2);
        cout <<"$" << setw(2) << loan_amount;
        cout << fixed << noshowpoint << setprecision(0);
        cout << setw(8) << years << " years";
        cout << fixed << showpoint << setprecision(1);
        cout << setw(10) << interest_rate << "%" << setw(8) << "$";
        cout << fixed << showpoint << setprecision(2);
        cout << setw(2) << monthly_payment << endl;
    }
    
    
    void func8(double total, double years, double interest_rate, double monthly_amount)
    {
        cout << "Total" << setw(29) << "Annual" << setw(12) << "Monthly" << endl;
        cout << "Amount" << setw(14) << "Number" << setw(16) << "Interest";
        cout << setw(10) << "Savings" << endl;
        cout << "Saved" << setw(17) << "of Years" << setw(10) << "Rate";
        cout << setw(15) << "Required" << endl;
        cout << "-----------  " << setw(3) << " -----------  ";
        cout << " --------  " << setw(3) << " ---------" << endl;
        cout << fixed << showpoint << setprecision(2);
        cout <<"$" << setw(2) << total;
        cout << fixed << noshowpoint << setprecision(0);
        cout << setw(6) << years << " years";
        cout << fixed << showpoint << setprecision(1);
        cout << setw(10) << interest_rate << "%" << setw(8) << "$";
        cout << fixed << showpoint << setprecision(2);
        cout << setw(2) << monthly_amount << endl;
    } 
         
    
    double func6(double interest_rate, double years)
    {
        
        return((interest_rate / 100) / 12);
    }
    
    double func5(double monthly_interest, double number_months, double years)
    {
        number_months = years * 12;
        return((exp(number_months * log(1 + monthly_interest))));
    }
    
    double func4(double total, double monthly_interest, double factor)
    {
        return((total * monthly_interest) / (factor - 1));
    }
    
    double func3(double factor, double monthly_amount, double monthly_interest)
    {
        return((((factor - 1) * monthly_amount) / monthly_interest));
    }   
    
    double func2(double factor, double monthly_payment, double monthly_interest)
    {
        return(((factor - 1) * monthly_payment) / (factor * monthly_interest));
    }
    
    double func1(double factor, double monthly_interest, double loan_amount)
    {
        return((factor * monthly_interest * loan_amount) / (factor - 1));
    }
  • vpawizard
    New Member
    • Nov 2006
    • 66

    #2
    Code:
    while(1)
    {
       /*menu and questions*/
     
       /*switch case*/
    
       case 5:
       /*Add following line*/
       exit(0);
    }

    Comment

    Working...