//Charlotte Davies-Kiernan CS1A Practice Practicum P. 296 #16 // /***************************************************************************** * * Compute Savings Balance *____________________________________________________________________________ * This program will calculate the balance of a savings account after a period * of time, taking into account annual interest rate, the starting balance, * and the number of months that have passed since the account was established. * * Formulas Used: * monthlyRate = annualRate / 12.0 * monthlyResult = balance * monthlyRate * ____________________________________________________________________________ * Input * annualRate //The annual interest earned in the savings account * startingBalance //The starting amount in the savings account * months //The amount of months that have passed * deposit //The amount deposited into the acount each month * withdrawl //The amount withdrawn from the account each month * * Output * balance //The total within the account after the time entered has passed * monthlyRate //The rate of interest calculate per month based off of annual interest * monthlyResult //The total amount of interest gained per month based off of the balance * totalDeposit //The total amount deposited into the account after so many months * totalWithdrawl //The total amount withdrawn from the account after so many months * totalInterest //The total amount of interest earned after so many months *****************************************************************************/ #include <iostream> #include <iomanip> using namespace std; int main() { //Data Dictionary float annualRate; //INPUT - The annual interest earned in the savings account float startingBalance; //INPUT - The starting amount in the savings account int months; //INPUT - The amount of months that have passed float deposit; //INPUT - The amount deposited into the acount each month float withdrawl; //INPUT - The amount withdrawn from the account each month float balance; //OUTPUT - The total within the account after the time entered has passed float monthlyRate; //OUTPUT - The rate of interest calculate per month based off of annual interest float monthlyResult; //OUTUT - The total amount of interest gained per month based off of the balance float totalWithdrawl; //OUTPUT - The total amount withdrawn from the account after so many months float totalDeposit; //OUTPUT - The total amount deposited into the account after so many months float totalInterest; //OUTPUT - The total amount of interest earned after so many months //User Input cout << "What is the annual interest rate? (in decimal form for example 10% = .10): " << endl; cin >> annualRate; cout << "What is the starting balance of the account?: " << endl; cin >> startingBalance; cout << "How many months have passed since the account was established?: " << endl; cin >> months; //Calculate totalDeposit = 0; totalWithdrawl = 0; totalInterest = 0; cout << fixed << setprecision(2); for(int i = 1; i <= months; i++){ cout << "What was the amount deposited during the " << i << " month?: " << endl; cin >> deposit; if(deposit < 0){ cout << "Invalid entry, please enter a positive amount!" << endl; cin >> deposit; } cout << "What was the amount withdrawn during the " << i << " month?: " << endl; cin >> withdrawl; if(withdrawl < 0){ cout << "Invalid entry, please enter a positive number!" << endl; cin >> withdrawl; } balance = startingBalance + deposit - withdrawl; //Monthly Interest monthlyRate = ((annualRate)/12.0); monthlyResult = (balance * monthlyRate); balance = monthlyResult + balance; startingBalance = balance; //Calculate Totals totalDeposit += deposit; totalWithdrawl += withdrawl; totalInterest += monthlyRate; } //Display Totals cout << "After " << months << " months your savings is, $" << balance << endl; cout << "After " << months << " months your total amount deposited was, $" << totalDeposit << endl; cout << "After " << months << " months your total amount withdrawn was, $" << totalWithdrawl << endl; cout << "After " << months << " months your total interest earned is, $" << totalInterest << endl; return 0; }
.10 10000.00 36 500 200 500 200 500 200 500
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