fork download
  1. //Yasmine Cervantes CS1A Ch. 5, P.296, # 16
  2. //
  3. /*******************************************************************************
  4. *
  5. * CALCULATING A SAVINGS ACCOUNT BALANCE
  6. *_______________________________________________________________________________
  7. * This program will calculate the balance of a savings account at the end of a
  8. * certain period of time. It will use annual interest rates, the starting
  9. * balance, and the total amount of months that have passed since the account was
  10. * established.
  11. * ______________________________________________________________________________
  12. * INPUT:
  13. * initialBalance - 10,000
  14. * annualInterest - 0.10
  15. * numberofMonths - 36
  16. * monthlyDeposit - 500 // user inputs
  17. * monthlyWithdrawal - 200 // user inputs
  18. *
  19. *
  20. * OUTPUT:
  21. * monthlyInterest - annualInterest / 12
  22. * totalDeposits - monthlyDeposit * numberofMonths
  23. * totalWithdrawn - monthlyWithdrawn * numberofMonths
  24. * totalinterestEarned - monthlyWithdrawn * numberofMonths
  25. * endingBalance - (initialBalance - totalmonthlyWithdrawn +
  26. * totalmonthlyDeposit) + totalinterestEarned
  27. *
  28. *
  29. *******************************************************************************/
  30. #include <iostream>
  31. using namespace std;
  32. int main()
  33. {
  34.  
  35. //Declaring Variables
  36. double initialBalance = 10000;
  37. double annualInterest = 0.10;
  38. double numberofMonths = 36;
  39. double monthlyDeposit = 0;
  40. double monthlyWithdrawn = 0;
  41.  
  42.  
  43. //Input
  44. cout << "Please insert amount of cash deposit for the month" << endl;
  45. cin >> monthlyDeposit;
  46.  
  47. cout << "Please insert amount of cash withdrawn for the month" << endl;
  48. cin >> monthlyWithdrawn;
  49.  
  50.  
  51.  
  52. // Calculations & output
  53. double totalmonthlyDeposit = monthlyDeposit * numberofMonths;
  54. cout << "Your total amount of monthly deposits is: " << totalmonthlyDeposit
  55. << endl;
  56.  
  57. double totalmonthlyWithdrawn = monthlyWithdrawn * numberofMonths;
  58. cout << "your total amount of monthly withdrawals is: " << totalmonthlyWithdrawn
  59. << endl;
  60.  
  61. double monthlyInterest = annualInterest / 12;
  62. cout << "Your monthly interest is: " << monthlyInterest << endl;
  63.  
  64. double totalinterestEarned = monthlyInterest * initialBalance;
  65. cout << "Your total amount of interest earned is: " << totalinterestEarned
  66. << endl;
  67.  
  68. double endingBalance = (initialBalance - totalmonthlyWithdrawn + totalmonthlyDeposit)
  69. + totalinterestEarned;
  70.  
  71. cout << "Your ending balance is: " << endingBalance << endl;
  72.  
  73.  
  74. return 0;
  75.  
  76. }
  77.  
  78.  
Success #stdin #stdout 0.01s 5436KB
stdin
500
200
stdout
Please insert amount of cash deposit for the month
Please insert amount of cash withdrawn for the month
Your total amount of monthly deposits is: 18000
your total amount of monthly withdrawals is: 7200
Your monthly interest is: 0.00833333
Your total amount of interest earned is: 83.3333
Your ending balance is: 20883.3