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