fork download
  1. //Andres Guzman CSC5 Chapter 3, P. 146, #16
  2. //
  3. /**************************************************************
  4. *
  5. * ANNUAL SAVING BALANCE CALCULATION
  6. * ____________________________________________________________
  7. * This program will calculate the compound interest
  8. * Computation is based on the formula:
  9. * Amount = Principal × (1 + Rate/T)^T
  10. ____________________________________________________________
  11. * INPUT
  12. * rate : the interest rate
  13. * com : times compounded(1, 2, 4, 12, 365)
  14. * principal : invested amount
  15. * OUTPUT
  16. * interest : the amount multiplied by rates
  17. * amount : total amount in savings
  18. **************************************************************/
  19.  
  20. #include <iostream>
  21. #include <iomanip>
  22. #include <cmath>
  23. using namespace std;
  24.  
  25. int main ()
  26. {
  27. float principal; //Input for invested number
  28. float rate; //Input for rate percentage
  29. float com; //Input for time compound
  30. //
  31. //Output results
  32. cout << "Interest Rate: ";
  33. cin >> rate;
  34. cout << "\nTimes Compounded: ";
  35. cin >> com;
  36. cout << "\nPrincipal: $ ";
  37. cin >> principal;
  38. //
  39. //Computation of formula
  40. rate/=100; //Output to turn rate into mathematical equivalent
  41. float amount = principal * (pow((1+ (rate/com)),com )); //Compound interest
  42. float interest = amount - principal; //Output sum after rate
  43. //
  44. //Output results
  45. cout << fixed << setprecision(2) << "\nInterest: $" << interest;
  46. cout << "\nAmount in Savings: $" << amount;
  47. return 0;
  48. }
Success #stdin #stdout 0s 5304KB
stdin
4.25 12 1000
stdout
Interest Rate: 
Times Compounded: 
Principal: $ 
Interest: $43.34
Amount in Savings: $1043.34