Programming Challenge Chapter 3 – Q #16 Interest Earned – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #16 Interest Earned – Tony Gaddis – Starting Out With C++


 







Problem: -

Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as


Principal is the balance in the savings account, Rate is the interest rate, and T is the number of times the interest is compounded during a year (T is 4 if the interest is compounded quarterly). 
Write a program that asks for the principal, the interest rate, and the number of times the interest is compounded. It should display a report similar to
                                     Interest Rate:                    4.25% 
                                     Times Compounded:        12
                                     Principal:                        $ 1000.00 
                                     Interest:                          $ 43.34 
                                     Amount in Savings:       $ 1043.34

Solution: -

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

      double principal, intrest_rate;

      int T;

      double total_intrest_rate = 0.0, ammount = 0.0, total_ammount = 0.0;

      cout << "Enter Balance of Saving Account: ";

      cin >> principal;

      cout << "Whta is The Intrest Rate in %: ";

      cin >> intrest_rate;

      cout << "Enter number of times the intrest compounded during a year; ";

      cin >> T;

      //Calculation

      intrest_rate /= 100.0;

      ammount = principal * pow((1 + intrest_rate / T), T);

      total_intrest_rate = ammount - principal;

      intrest_rate *= 100;

      total_ammount = principal + total_intrest_rate;

      cout << setprecision(2) << showpoint << fixed;

      cout << "intrest Rate:        " << setw(8) << intrest_rate << "%" << endl;;

      cout << "Time Compounded:     " << setw(8) << T << endl;

      cout << "Principle:          $" << setw(8) << principal << endl;

      cout << "Intrest:            $" << setw(8) << total_intrest_rate << endl;

      cout << "Ammount in Saving:  $" << setw(8) << total_ammount << endl;

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution

  1. Add two header file for math and pattern.
  2. Declare two double variables for input.
  3. Declare another a int variable for input.
  4. Declare two double variable for calculations.
  5. Take input one by one from user.
  6. Calculate the values.
  7. Calculate the values by using given formula.
  8.  In last, display output on the screen in a pattern.
  9. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File



Post a Comment

0 Comments