Function call - The calculation function call not returning the calculations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

 //Function prototypes
 char display_Menu();
 double money();
 double Interest();
 int Years();
 double loan(char& computing_choice, double& loanAmount, double& interest_rate, int years);
 double factor (double Year,double interest_rate);

int main()
{
 char display,show,Choice,compute_choice;
 double  Calculation, sum, extra_rate,  months;
 double amount,moneyAmount,monthly_amount;
 double rate, moneyRate,Calc;
 int years, period,time;
 
 do
   {
    //Function Calls
    display = display_Menu();
    moneyAmount = money ();
    rate = Interest();
    years = Years();
    Calculation =  loan( compute_choice, sum, 
    extra_rate,period );
  
      
    cout << endl << endl<< endl;
    cout << fixed << setprecision(2);
    cout << setw(4) <<" Loan Amount " << setw(10)<<" Years ";      
    cout << setw(23) <<" Annual Interest Rate ";
    cout << setw(19)<< "Monthly Payment " <<endl; 
    cout << setw(10) << moneyAmount;      
    cout << setw(11) <<years;
    cout << setw(16) << rate<< setw(19)<<Calculation <<endl; 
    
    Choice = toupper(Choice);
   } while (Choice != 'E');
   return 0; 
 
  
  cout<<endl<<endl;
  cout << "Press [enter] to exit" <<endl;
  cin.ignore(); //needed because of keyboard input
  cin.get();
  return 0;
}
// Function displays the choices and user input
 char display_Menu()
 {  
    char Choice;
    cout << endl; 
    cout << " This program computes loan and/or saving calculations." 
    << endl;
    cout << endl;
    cout <<" Please choos a program to calculate: " << endl;
    cout << "    L - Compute a Loan payment" << endl;
    cout << "    A - Compute a loan Amount" << endl;
    cout << "    S - Compute total amount saved" << endl;
    cout << "    M = Compute monthly amount" << endl;
    cout << "    E - Exit Program" << endl;
    cout << endl;
    cout << endl;
    cout <<" Enter choice from Menu above: ";
    cin >> Choice;
    cout << endl;
    Choice = toupper(Choice);
    if ((Choice != 'L') && (Choice != 'A') &&
    (Choice != 'S') && (Choice != 'M')&& (Choice != 'E'))
    {
         cout <<" Please enter a choice from above" << endl;
         cin >> Choice;
    }
    if (Choice == 'E')
    {
        return 0;
    } 
    return (Choice);
    
  }
 
 // function get the  loan amount and error checks for a valid
 //monetary amount.   
 double money()
  {
    double LoanAmount;
    cout <<" The amount of loan you need to receive? "; 
    cin >> LoanAmount; 
    
   while ((LoanAmount <= 0)||(LoanAmount >999999.99 ))
    {
         cout <<" The amount of you entered is invalid? " <<endl;
         cout <<" Please enter a valid amount ";
         cin >> LoanAmount;
    }  
     return (LoanAmount);   
  }
 
 //Function askes for the Annual interest rate and error checks
 // that the percentage is between 1 and 305
 double Interest()
 {
    double Interest_Rate;
    cout <<" Enter an Annual interest rate: ";
    cin >> Interest_Rate;
    
    while ((Interest_Rate >30)||(Interest_Rate <= 1))
    {
         
         cout <<" Enter interest rate lower than 30% and higher than 1% "; 
         cin >> Interest_Rate;
         
    }
    
    
    return (Interest_Rate);
 }
 
 //function allows the user to input the terms of the loan and
 // error checks -the terms must be  betweeen 50 and 1 year
  int Years()
 {
    int Term_Years;
    cout <<" Enter a term in whole years: ";
    cin >> Term_Years;
    while ((Term_Years > 50)||(Term_Years < 1))
    {
         cout <<" Years must be between one and fifty, Please try again "; 
         cin >> Term_Years;
    }
    return (Term_Years);
 }
 
 //The function does the claculations based upon the user input
 double loan( char& computing_choice, double& loanAmount, 
 double& interest_rate,int years)       {
  
    int months = years * 12;
    double rate;
    double Calc;
    double monthlyRate = rate/100;
    double equation = factor(months,monthlyRate);
    
     
    
    switch (toupper(computing_choice))  {
         
         case 'L':
              Calc = equation * monthlyRate * loanAmount /(equation-1);         
              break;
          
         case 'A':
              Calc = (equation-1) * loanAmount / (equation * monthlyRate);        
              break; 
              
         case 'S':
              Calc = (equation-1) * loanAmount / monthlyRate;
              break; 
                         
         case 'M': 
              Calc = loanAmount * monthlyRate/(equation-1);  
             break; 
           }
            return (Calc); 
          }
   
 //equations used to calculate the loans and savings  
   double factor (double Year,double interest_rate)
   {
     
     
     return pow (1+interest_rate,Year);
   }    
Is there a question here somewhere?

I don't see any 'calculation' function.
there is one, it's also the only function that is inconsistent with the rest in terms of brace style.
If I can give you one piece of advice: BE CONSISTENT
Last edited on
Topic archived. No new replies allowed.