Guest User

Untitled

a guest
Jul 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. The program first will prompt for and obtain the following input:
  2.  
  3. Starting balance;
  4.  
  5. The annual interest rate, entered in decimal format, e.g., 5% is 5 not .05;
  6.  
  7. Number of months of the savings account (not a fixed 3 months as in the book problem).
  8.  
  9. The program next will use a a loop, one iteration for each month, to prompt for and obtain the following input:
  10.  
  11. Total amount deposited in the account for each month, which will be added to the balance;
  12.  
  13. Total amount withdrawn from the account each month, which will be subtracted from the balance.
  14.  
  15. In each month's iteration, the program also will calculate the interest for that month and add that interest to balance. As the book states, interest will be calculated on the average of the starting and ending balances for that month.
  16.  
  17.  
  18.  
  19. After the loop finishes, the program will display a final report that includes the following information (N refers to the number of months the user entered):
  20.  
  21. Starting balance at the beginning of the N-month period.
  22.  
  23. Total deposits made during the N months.
  24.  
  25. Total withdrawals made during the N months.
  26.  
  27. The total interest posted to the account during the N-month period.
  28.  
  29. Final balance at the end of the N months.
  30.  
  31. Below is a sample run with sample input data. This is only a sample run of what will be displayed if the user enters the input data shown. You should make sure that the program works correctly for any reasonable input data that the user enters by testing it with other input values. What the user types in follows the ===>
  32.  
  33.  
  34.  
  35. Sample Run #1:
  36.  
  37.  
  38.  
  39. Enter the initial balance ===> 1000
  40.  
  41. Enter the number of months to cover: ===> 3
  42. Enter the annual interest rate (decimal format; e.g., 5 not .05) ===> 10
  43. Enter the amount deposited for month 1 ===> 500
  44. Enter the amount withdrawn for month 1 ===> 400
  45. Enter the amount deposited for month 2 ===> 600
  46. Enter the amount withdrawn for month 2 ===> 700
  47. Enter the amount deposited for month 3 ===> 800
  48. Enter the amount withdrawn for month 3 ===> 900
  49.  
  50. Starting balance: $ 1000.00
  51. Total amount deposited: $ 1900.00
  52. Total amount withdrawn: $ 2000.00
  53. Total interest earned: $ 25.64
  54. Final balance: $ 925.64
  55.  
  56.  
  57.  
  58. Input Validation
  59.  
  60.  
  61.  
  62. You need to perform the following input validation:
  63.  
  64. Do not accept a negative numbers for the amount deposited (you may assume the user entered a number, but you can't assume the user entered 0 or a positive number).
  65.  
  66. Do not accept a negative numbers for the amount withdrawn (you may assume the user entered a number, but you can't assume the user entered 0 or a positive number).
  67.  
  68. Do not accept an amount withdrawn that would result in the account being overdrawn (withdrawal greater than sum of starting balance and deposit).
  69.  
  70. If input validation fails, then the user is warned of the problem and prompted to enter the information again. The user does not have the option to quit (a good program really should give that option but I don't want to make this assignment more complicated than it already is).
  71.  
  72.  
  73.  
  74. Below is a sample run with sample input data. This is only a sample run of what will be displayed if the user enters the input data shown. You should make sure that the program works correctly for any reasonable input data that the user enters by testing it with other input values. What the user types in follows the ===>
  75.  
  76.  
  77.  
  78. Sample Run #2:
  79.  
  80.  
  81.  
  82. Enter the initial balance ===> 1234.50
  83.  
  84. Enter the number of months to cover: ===> 3
  85. Enter the annual interest rate (decimal format; e.g., 5 not .05) ===> 7
  86. Enter the amount deposited for month 1 ===> -99
  87. Please enter a non-negative amount ====> -80
  88. Please enter a non-negative amount ====> -234
  89. Please enter a non-negative amount ====> 99
  90. Enter the amount withdrawn for month 1 ===> -200
  91. Withdrawal must not be negative and not greater than the current balance of $1333.50
  92. Please re-enter the withdrawal amount ====> -100
  93. Withdrawal must not be negative and not greater than the current balance of $1333.50
  94. Please re-enter the withdrawal amount ====> 200
  95. Enter the amount deposited for month 2 ===> 0
  96. Enter the amount withdrawn for month 2 ===> 1000.89
  97. Enter the amount deposited for month 3 ===> 109.88
  98. Enter the amount withdrawn for month 3 ===> 3456.89
  99. Withdrawal must not be negative and not greater than the current balance of $253.13
  100. Please re-enter the withdrawal amount ====> 3000.88
  101. Withdrawal must not be negative and not greater than the current balance of $253.13
  102. Please re-enter the withdrawal amount ====> 2666.88
  103. Withdrawal must not be negative and not greater than the current balance of $253.13
  104. Please re-enter the withdrawal amount ====> 253.13
  105. Withdrawal must not be negative and not greater than the current balance of $253.13
  106. Please re-enter the withdrawal amount ====> 253.00
  107.  
  108. Starting balance: $ 1234.50
  109. Total amount deposited: $ 208.88
  110. Total amount withdrawn: $ 1453.89
  111. Total interest earned: $ 11.06
  112. Final balance: $ 0.55
  113.  
  114.  
  115.  
  116.  
  117.  
  118. Suggestions for Program Development!!
  119.  
  120.  
  121.  
  122. While this program is well within your capabilities, it is relatively complex, so a good strategy is to write it in stages, rather than try to write it all at once. I strongly suggest the following order:
  123.  
  124. No interest and no input validation. That is, do not input the annual interest rate and assume that the user gives valid amounts for each month's deposits and withdrawals. Try to get the loop running the proper number of times so that the balance is accurately updated without applying any interest. See the sample run below.
  125.  
  126. Add input validation that the amount deposited or withdrawn cannot be negative
  127.  
  128. Add input validation to prevent the account from being overdrawn.
  129.  
  130. Add the user input of the annual interest rate and calculate the interest for each month and the total interest earned. I believe that this is the most difficult part of the assignment because of the way the interest is calculated and applied at the end of each month as described above and in the textbook. That is why I would strongly advise you to leave it to last. You will still receive a good deal of credit for this assignment if you include everything but the interest. (Without the interest, of course, your final balance will be different in the sample runs shown above.)
  131.  
  132.  
  133.  
  134. Sample Run following suggestion #1 above (no interest and no input validation):
  135.  
  136.  
  137.  
  138. Enter the initial balance ===> 1000
  139.  
  140. Enter the number of months to cover: ===> 3
  141. Enter the amount deposited for month 1 ===> 500
  142. Enter the amount withdrawn for month 1 ===> 400
  143. Enter the amount deposited for month 2 ===> 600
  144. Enter the amount withdrawn for month 2 ===> 700
  145. Enter the amount deposited for month 3 ===> 800
  146. Enter the amount withdrawn for month 3 ===> 900
  147.  
  148. Starting balance: $ 1000.00
  149. Total amount deposited: $ 1900.00
  150. Total amount withdrawn: $ 2000.00
  151. Final balance: $ 900.00
Add Comment
Please, Sign In to add comment