fork download
  1. //Charlotte Davies-Kiernan CS1A Practice Practicum P. 296 #16
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Compute Savings Balance
  6.  *____________________________________________________________________________
  7.  * This program will calculate the balance of a savings account after a period
  8.  * of time, taking into account annual interest rate, the starting balance,
  9.  * and the number of months that have passed since the account was established.
  10.  *
  11.  * Formulas Used:
  12.  * monthlyRate = annualRate / 12.0
  13.  * monthlyResult = balance * monthlyRate
  14.  * ____________________________________________________________________________
  15.  * Input
  16.  * annualRate //The annual interest earned in the savings account
  17.  * startingBalance //The starting amount in the savings account
  18.  * months //The amount of months that have passed
  19.  * deposit //The amount deposited into the acount each month
  20.  * withdrawl //The amount withdrawn from the account each month
  21.  *
  22.  * Output
  23.  * balance //The total within the account after the time entered has passed
  24.  * monthlyRate //The rate of interest calculate per month based off of annual interest
  25.  * monthlyResult //The total amount of interest gained per month based off of the balance
  26.  * totalDeposit //The total amount deposited into the account after so many months
  27.  * totalWithdrawl //The total amount withdrawn from the account after so many months
  28.  * totalInterest //The total amount of interest earned after so many months
  29.  *****************************************************************************/
  30. #include <iostream>
  31. #include <iomanip>
  32. using namespace std;
  33. int main() {
  34. //Data Dictionary
  35. float annualRate; //INPUT - The annual interest earned in the savings account
  36. float startingBalance; //INPUT - The starting amount in the savings account
  37. int months; //INPUT - The amount of months that have passed
  38. float deposit; //INPUT - The amount deposited into the acount each month
  39. float withdrawl; //INPUT - The amount withdrawn from the account each month
  40. float balance; //OUTPUT - The total within the account after the time entered has passed
  41. float monthlyRate; //OUTPUT - The rate of interest calculate per month based off of annual interest
  42. float monthlyResult; //OUTUT - The total amount of interest gained per month based off of the balance
  43. float totalWithdrawl; //OUTPUT - The total amount withdrawn from the account after so many months
  44. float totalDeposit; //OUTPUT - The total amount deposited into the account after so many months
  45. float totalInterest; //OUTPUT - The total amount of interest earned after so many months
  46. //User Input
  47. cout << "What is the annual interest rate? (in decimal form for example 10% = .10): " << endl;
  48. cin >> annualRate;
  49. cout << "What is the starting balance of the account?: " << endl;
  50. cin >> startingBalance;
  51. cout << "How many months have passed since the account was established?: " << endl;
  52. cin >> months;
  53. //Calculate
  54. totalDeposit = 0;
  55. totalWithdrawl = 0;
  56. totalInterest = 0;
  57. cout << fixed << setprecision(2);
  58. for(int i = 1; i <= months; i++){
  59. cout << "What was the amount deposited during the " << i << " month?: " << endl;
  60. cin >> deposit;
  61. if(deposit < 0){
  62. cout << "Invalid entry, please enter a positive amount!" << endl;
  63. cin >> deposit;
  64. }
  65. cout << "What was the amount withdrawn during the " << i << " month?: " << endl;
  66. cin >> withdrawl;
  67. if(withdrawl < 0){
  68. cout << "Invalid entry, please enter a positive number!" << endl;
  69. cin >> withdrawl;
  70. }
  71. balance = startingBalance + deposit - withdrawl;
  72. //Monthly Interest
  73. monthlyRate = ((annualRate)/12.0);
  74. monthlyResult = (balance * monthlyRate);
  75. balance = monthlyResult + balance;
  76. startingBalance = balance;
  77. //Calculate Totals
  78. totalDeposit += deposit;
  79. totalWithdrawl += withdrawl;
  80. totalInterest += monthlyRate;
  81. }
  82. //Display Totals
  83. cout << "After " << months << " months your savings is, $" << balance << endl;
  84. cout << "After " << months << " months your total amount deposited was, $" << totalDeposit << endl;
  85. cout << "After " << months << " months your total amount withdrawn was, $" << totalWithdrawl << endl;
  86. cout << "After " << months << " months your total interest earned is, $" << totalInterest << endl;
  87. return 0;
  88. }
Success #stdin #stdout 0.01s 5308KB
stdin
.10
10000.00
36
500
200
500
200
500
200
500
stdout
What is the annual interest rate? (in decimal form for example 10% = .10): 
What is the starting balance of the account?: 
How many months have passed since the account was established?: 
What was the amount deposited during the 1 month?: 
What was the amount withdrawn during the 1 month?: 
What was the amount deposited during the 2 month?: 
What was the amount withdrawn during the 2 month?: 
What was the amount deposited during the 3 month?: 
What was the amount withdrawn during the 3 month?: 
What was the amount deposited during the 4 month?: 
What was the amount withdrawn during the 4 month?: 
What was the amount deposited during the 5 month?: 
What was the amount withdrawn during the 5 month?: 
What was the amount deposited during the 6 month?: 
What was the amount withdrawn during the 6 month?: 
What was the amount deposited during the 7 month?: 
What was the amount withdrawn during the 7 month?: 
What was the amount deposited during the 8 month?: 
What was the amount withdrawn during the 8 month?: 
What was the amount deposited during the 9 month?: 
What was the amount withdrawn during the 9 month?: 
What was the amount deposited during the 10 month?: 
What was the amount withdrawn during the 10 month?: 
What was the amount deposited during the 11 month?: 
What was the amount withdrawn during the 11 month?: 
What was the amount deposited during the 12 month?: 
What was the amount withdrawn during the 12 month?: 
What was the amount deposited during the 13 month?: 
What was the amount withdrawn during the 13 month?: 
What was the amount deposited during the 14 month?: 
What was the amount withdrawn during the 14 month?: 
What was the amount deposited during the 15 month?: 
What was the amount withdrawn during the 15 month?: 
What was the amount deposited during the 16 month?: 
What was the amount withdrawn during the 16 month?: 
What was the amount deposited during the 17 month?: 
What was the amount withdrawn during the 17 month?: 
What was the amount deposited during the 18 month?: 
What was the amount withdrawn during the 18 month?: 
What was the amount deposited during the 19 month?: 
What was the amount withdrawn during the 19 month?: 
What was the amount deposited during the 20 month?: 
What was the amount withdrawn during the 20 month?: 
What was the amount deposited during the 21 month?: 
What was the amount withdrawn during the 21 month?: 
What was the amount deposited during the 22 month?: 
What was the amount withdrawn during the 22 month?: 
What was the amount deposited during the 23 month?: 
What was the amount withdrawn during the 23 month?: 
What was the amount deposited during the 24 month?: 
What was the amount withdrawn during the 24 month?: 
What was the amount deposited during the 25 month?: 
What was the amount withdrawn during the 25 month?: 
What was the amount deposited during the 26 month?: 
What was the amount withdrawn during the 26 month?: 
What was the amount deposited during the 27 month?: 
What was the amount withdrawn during the 27 month?: 
What was the amount deposited during the 28 month?: 
What was the amount withdrawn during the 28 month?: 
What was the amount deposited during the 29 month?: 
What was the amount withdrawn during the 29 month?: 
What was the amount deposited during the 30 month?: 
What was the amount withdrawn during the 30 month?: 
What was the amount deposited during the 31 month?: 
What was the amount withdrawn during the 31 month?: 
What was the amount deposited during the 32 month?: 
What was the amount withdrawn during the 32 month?: 
What was the amount deposited during the 33 month?: 
What was the amount withdrawn during the 33 month?: 
What was the amount deposited during the 34 month?: 
What was the amount withdrawn during the 34 month?: 
What was the amount deposited during the 35 month?: 
What was the amount withdrawn during the 35 month?: 
What was the amount deposited during the 36 month?: 
What was the amount withdrawn during the 36 month?: 
After 36 months your savings is, $26120.82
After 36 months your total amount deposited was, $18000.00
After 36 months your total amount withdrawn was, $7200.00
After 36 months your total interest earned is, $0.30