fork(1) download
  1. // Nicolas Ruano CS1A Chapter 3 Pp. 146 #16
  2. /*******************************************************************************
  3.  * CALCULATING
  4. *******************************************************************************/
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <cmath>
  8. #include <string>
  9. #include <cstdlib>
  10. using namespace std;
  11.  
  12. int main() {
  13. double principal;
  14. double annualRate;
  15. double interest;
  16. double amount;
  17. int timesCompounded;
  18.  
  19.  
  20. //INPUT
  21. cout << "Enter the Principal amount: $1000\n";
  22. cin >> principal;
  23.  
  24. cout << "Enter the annual interest rate: 4.25\n";
  25. cin >> annualRate;
  26.  
  27. cout << "Enter the number of times interest is compounded per year: 12\n";
  28.  
  29. //PROCESSING THE INPUT on the annualRate
  30. double rateDecimal = annualRate / 100.0;
  31.  
  32. //PROCCESSING THE INPUT using the compund interest formula
  33. amount = principal * pow(1 + rateDecimal / timesCompounded,
  34. timesCompounded);
  35.  
  36. //PROCESS FINAL Results on interests earned
  37. interest = amount - principal;
  38.  
  39. //OUTPUT - Displaying report
  40. cout << fixed << setprecision(2);
  41. cout << "\n---Savings Account Report ---\n";
  42. cout << "Interest Rate: " << annualRate << "4.25%" << endl;
  43. cout << "Times Compounded: 12" << timesCompounded << endl;
  44. cout << "Principal: $43.34" << principal << endl;
  45. cout << "Interest: $1000" << interest << endl;
  46. cout << "Amount in Savings: $1043.34" << amount << endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5284KB
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: 0.004.25%
Times Compounded: 120
Principal: $43.340.00
Interest: $10000.00
Amount in Savings: $1043.340.00