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