fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7. double principal, annualRate, interest, amount;
  8. int timesCompounded;
  9.  
  10. //INPUT
  11. cout << "Enter the Principal amount: $1000\n";
  12. cin >> principal;
  13.  
  14. cout << "Enter the annual interest rate: 4.25\n";
  15. cin >> annualRate;
  16.  
  17. cout << "Enter the number of times interest is compounded per year: 12\n";
  18.  
  19. //PROCESSING THE INPUT on the annualRate
  20. double rateDecimal = annualRate / 100.0;
  21.  
  22. //PROCCESSING THE INPUT using the compund interest formula
  23. amount = principal * pow(1 + rateDecimal / timesCompounded,
  24. timesCompounded);
  25.  
  26. //PROCESS FINAL Results on interests earned
  27. interest = amount - principal;
  28.  
  29. //OUTPUT - Displaying report
  30. cout << fixed << setprecision(2);
  31. cout << "\n---Savings Account Report ---\n";
  32. cout << "Interest Rate: 4.25 " << annualRate << "%" << endl;
  33. cout << "Times Compounded: " << timesCompounded << endl;
  34. cout << "Principal: $1000.00" << principal << endl;
  35. cout << "Interest: $43.34" << interest << endl;
  36. cout << "Amount in Savings : $1043.34" << amount << endl;
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Enter the Principal amount: $1000
Enter the annual interest rate: 4.25
Enter the number of times interest is compounded per year: 12

---Savings Account Report ---
Interest Rate: 4.25 0.00%
Times Compounded: 0
Principal: $1000.000.00
Interest: $43.340.00
Amount in Savings : $1043.340.00