Write a program to output accumulated values

Assignment Help C/C++ Programming
Reference no: EM13762976

The following formula will compute the Total Amount that will be accumulated for a given Monthly Amount saved:

Notice that his formula also requires that you first calculate a factor and then use it in your formula. The factor formula is:

factor = exp( numberOfMonths * log(1 + monthlyInterestRate))

exp and log are predefined mathematical functions, located in the C++ library.

For hand calculating results to test your program, the equivalent algebraic equation is:

factor = (1 + monthlyInterestRate) numberOfMonths

Write a program to output accumulated values for each month, given a set amount saved each month, until the accumulated amount reaches a set goal amount.

Discussion about comparing floating point values:

Given two floating point values:

num = 9.99999999

num2 = 10.00000000

If both are displayed to two decimal places, you will see:

10.00 and 10.00

However, if you compare the same two values within your code, to see if they are equal, the comparison test will be false (i.e. they are not equal).

This can cause problems for programs that compare floating point values.

But we can fix this problem by forcing the stored value to be rounded to 2 decimal places (not just the output value).

The formula:

num = floor((num * 100) + 0.5) / 100.0;

will change the value stored in num to be:

num = 10.00000000

And then if you compare num with num2, they will be found to be equal.

Requirements:

Ensure that you define constants for all fixed values. After defining the constants:

- Use only the constant name in your code (no hardcoded constant values).

- The usage of only constant names includes references in the executable code, the prompts and error messages, and the comments -- no hardcoded values anywhere!

Use the double data type for all floating point values.

The program should:

. Tell the user what the program does before prompting for input.

. Read from the user the amount that will be saved each month.

o The user must enter a value between $5 and $5000 inclusive. If they do not, issue an error message and then re-prompt the user to enter the number again, until a valid value is entered.

. Read from the user the annual interest rate.

o The user must enter a value between 1% and 25% inclusive. If they do not, issue an error message and then re-prompt the user to enter the number again, until a valid value is entered.

o After reading a valid value, the program will need to convert the annual interest rate to a monthly interest rate (divide by 100 to get a fractional interest rate, and then divide that by 12 for monthly interest) before using it in the formulas.

. Read from the user the goal amount they wish to reach.

o The user must enter a positive amount of no more than $ 999,999.99 (i.e. under 1 million). If they do not, issue an error message and then re-prompt the user to enter the number again, until a valid value is entered.

. Determine the factor and the total amount accumulated as calls to two different user-defined functions.

o The first function will return the factor for a specific number of months.

o The second function will return the total amount accumulated for a specific number of months

o Pass any required information, including the number of months to calculate the value for, to the functions as parameters.

. Display the month number and the total amount accumulated, for every month until the goal is reached, formatted as shown in the output example below.

o NOTE: Use the rounding formula provided above to round the value returned from the function and stored in the total amount accumulated variable to 2 decimal places, before comparing it to any other value.

. The program should cease displaying these values as soon as the total amount accumulated is at or above the goal.

. After the goal has been reached, display the annual interest rate, savings per month, total number of months, and final amount accumulated formatted as shown in the output example below.

Sample Input

Program will calculate the amount accumulated every month you save, until you reach your goal.

Enter the dollar amount to be saved each month: 1

Invalid amount -- must save between 5 and 5000 dollars a month. Try again.

Enter the dollar amount to be saved each month: 333.33

Enter the annual interest rate (between 1 and 25): 5.55

Enter the dollar amount of your goal: 5000

Sample Output

Note that dollar amounts are calculated to the nearest penny (i.e. rounded to 2 decimal places), and the annual interest rate is displayed to 3 decimal places with a % after it.

Month Total

Number Accumulated

------ -----------

1 333.33

2 668.20

3 1004.62

4 1342.60

5 1682.14

6 2023.25

7 2365.94

8 2710.21

9 3056.07

10 3403.54

11 3752.61

12 4103.29

13 4455.60

14 4809.54

15 5165.11

Reference no: EM13762976

Questions Cloud

Write summary of glaucons intensification of thrasymachu : Write a two page summary of Glaucon's intensification of Thrasymachus' argument at the beginning of Book II. First Glaucon will say Thrasymachus let Socrates off too easily.
How information system increase a company position : Define data. Define information. Describe what knowledge is and how it is used to create technology systems. How does an information system increase a company's competitive position
Discussion on meeting compliance requirements : Propose three factors that should be considered when designing policies for legal and regulatory compliance. Determine how each factor would minimize liability for the organization.
Long-term interest rates and future short-term interest rate : Provide an answer and a short (2-3 sentences) explanation for each of the following questions related to the quantitative easing measures. a. If long-term interest rates and future short-term interest rates increase, what is a reasonable change of t..
Write a program to output accumulated values : Write a program to output accumulated values for each month, given a set amount saved each month, until the accumulated amount reaches a set goal amount.
Explain the dystopian perspective in literature : Develop a broad understanding and empathetic view of women. Explain the dystopian perspective in literature. Identify the woman's voice in literature.
The role of social marketing in promoting public health : Describe any economic factors and funding intervention strategies that will address the issue.
Project managers and ethics-leadership and technology : Project managers do a lot more than calculations and reporting; they must keep the team on track, ensure ethical decisions are made, deal with conflict, and, depending on the type of organization, they may perform employee evaluations, issue bonus..
What observations about stores customers does angelou make : What observations about the stores customers does angelou make?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd