Question

In: Computer Science

Write a program that calculates the compound interest for an investment. (C++ coding language) If you...

Write a program that calculates the compound interest for an investment. (C++ coding language)

If you deposit an amount of money P , the principal, at an interest rate r then the interest will compound over time. This means that the interest earned each period becomes part of the principal and the next time you get interest you earn interest on the interest. This is known as compounding.

The equation for compound interest is

( r)n·t Pn=P0 1+n

where P0 is the starting amount in-
vested, Pn is the ending amount, r is
the annual interest rate as a
decimal, and n is the number of compounding periods per year, and t is the number of years.

The user will enter the starting principal, the annual interest rate as a percentage, the number of compounding periods per year, and the number of years.

The program calculates the interest earned and the final principal.

The two principals, the interest, and the interest rate must be doubles. The number of compounding periods and the number of years must be integers.

Your program must also include comments with your name, the date, and a short description of the project. It must also print this information as a splash screen at the beginning of the program run.

Princ. Start $1000.00
Interest Rate 6%

Periods

12
Years 10
Interest $819.40
Princ. End $1819.40

Use this as a template:

// Pound includes - will need the string and cmath libraries

#include<iostream>

#include<iomanip>

#include<cmath>

#include<string>

using namespace std;

int main(void) {

// Splash Screen

// Declare and Initialize all of the variables

// Will need doubles for starting and ending principal, and annual interest

// rate, and interest earned

// Integers for number of compounding periods per year, and number of years

int periods_per_year;

double start_principle;

// Prompt for entering data

// Calculate the final amount

// Calculate the interest earned

// Print the results

return 0;

}

Solutions

Expert Solution

Thanks for the question.
Here is the completed code for this problem.

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer. Thanks!
===========================================================================

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;

int main(void) {

   // Splash Screen
   cout<<"===============================================================\n";
   cout<<"Program calculate the Compund Interest of an Initial Investment\n";
   cout<<"===============================================================\n\n";
   // Declare and Initialize all of the variables
   // Will need doubles for starting and ending principal, and annual interest
   // rate, and interest earned
   double principal, ending_principal, annual_interest, interest_earned;
   // Integers for number of compounding periods per year, and number of years
   int periods, years;
   // Prompt for entering data
   cout<<"Enter the initial principal amount: "; cin >> principal;
   cout<<"Enter the annual interest rate as percentage: "; cin >> annual_interest;
   cout<<"Enter the number of years: "; cin >> years;
   cout<<"Enter period of compounding per year: "; cin >> periods;
   // Calculate the final amount
   ending_principal = principal*pow((1+annual_interest*0.01/periods),periods*years);
   // Calculate the interest earned
   interest_earned = ending_principal-principal;
   // Print the results
   cout<<setprecision(2)<<fixed<<showpoint;
   cout<<"\nInterest Earned: $"<<interest_earned<<endl;
   cout<<"Ending Principal: $"<<ending_principal<<endl;
   return 0;

}

=================================================================


Related Solutions

In coding language C, Write a program in which will use floating point variable (input=232.346) and...
In coding language C, Write a program in which will use floating point variable (input=232.346) and print out: 1. scientific notation form of input. 2. floating point form of input with total width 12 (default right aligned). 3. floating point form of input with total width 12 (default right aligned) and add 0s for unused space. 4. floating point form of input with total width 12 (left aligned). 5. floating point form of input with total width 12 (default right...
Coding in C++: For this verse, you need to write a program that asks the user...
Coding in C++: For this verse, you need to write a program that asks the user to input the inventory id number (integer) and the price (float) for 5 inventory items. Once the 5 inventory items are input from the user, output the results to the screen. Please ensure you use meaningful names for your variables. If your variables are not named meaningfully, points will be deducted.
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor. Your program should display the following: How...
In C++, Write a program that calculates pay for either an hourly paid worker or a...
In C++, Write a program that calculates pay for either an hourly paid worker or a salaried worker. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are paid their regular salary plus any bonus they may have earned. The program should declare two structures for the following data: Hourly Paid: HoursWorked HourlyRate Salaried: Salary Bonus The program should also declare a union with two members. Each member should be a structure...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT