Programming Challenge Chapter 3 – Q #16 Interest Earned – Tony Gaddis – Starting Out With C++
Problem: -
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
- Add two header file for math and pattern.
- Declare two double variables for input.
- Declare another a int variable for input.
- Declare two double variable for calculations.
- Take input one by one from user.
- Calculate the values.
- Calculate the values by using given formula.
- In last, display output on the screen in a pattern.
- Return 0 to the main function.
0 Comments