my calculator only outputs the total value, need it to show the total after each year. Do not worry about the other two cases just need help with the first calculator
void investmentcalculator();
void mortgageloancalculator();
void autoloancalculator();
int main()
{
void displayMenu();
int choice; // Menu choice should be 1, 2, 3 or 4
// Display the menu of choices
displayMenu();
// Get the user's choice
cin >> choice;
// Tell the user what he or she picked
switch (choice) {
case 1:
investmentcalculator();
break;
case 2:
mortgageloancalculator();
break;
case 3:
autoloancalculator();
break;
case 4:
break;
default:
cout << "Error, invalid selection, please choose one of the following" << endl;
displayMenu();
break;
}
system("pause");
return 0;
}
void displayMenu()
{
cout << "Choose a one of the calculators. \n\n";
cout << "1 Investment Calculator \n" << "2 Mortagage Loan Calculator \n" << "3 Auto loan Calculator \n" << "4 quit \n";
}
void investmentcalculator()
{
double total, principle, rate, years;// using double as we might have decimal values
int counter, choice;
string fname, lname;
counter = 0;
cout << "What is your first name and last name? " << endl;
cin >> fname >> lname;
cout << "How much would you like to invest? " << endl;
cin >> principle;
cout << "How much is your expected anual rate of return? " << endl;
cin >> rate;
cout << "How many years would you like to invest for?" << endl;
cin >> years;
total = (principle * (pow(E, (rate * years))));
cout << "The amount invested $ " << principle << " at an intrest rate of " << rate << " percent for " << years << " year(s)." << endl;
cout << fname + " " + lname << " will have $" << (principle * (pow(E, (rate * years)))) << " in" << years << " years" << endl;
cout << "do you want to see your annual yeilds? (1 = Yes/2 = No)" << endl;
cin >> choice;
switch (choice)
{
case 1:
do
{
cout.setf(ios::fixed);
cout.precision(2);
cout << counter << setw(21) << "$ " << total << endl;
} while (counter++ >= years);
break;
case 2:
{cout << "Ok, thank you. this program will now exit.";
system("pause");
break;
You can delete the line constdouble E = 2.718;, it isn't needed. As an aside, if you ever did need to find E raised to some power, you would use the exp() function.
The interest calculation:
total = (principle * (pow(E, (rate * years))));
as I said, you don't need E. What you do need, is the interest rate (which is a percentage) converted to a decimal. Then raise 1 + interest rate to the power years.
It would look like this:
total = principal * pow( 1.0 + rate/100.0, years ) ;
Example, if the interest rate is 3% the calculation uses 1 + 3/100 or 1.03 .
For the individual years, you need a loop, a for-loop is easiest, something like
for (int y = 1; y <= years; y++)
and then in the calculation, use y instead of years: