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

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...
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...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement for a salesperson at a rate of $0.35 per mile. Your program should interact (ask the user to enter the data) with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading > 13505.2 Enter ending odometer reading > 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89. ** Extra credit 6 points: Format the answer (2 points),...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT