Write a program that can calculate the future and present value of an investment given various parameters. When you calculate the future value of an investment, the more years you hold the investment and the higher the rate of return, the more valuable it is. For example, a $1000 investment at 7% return will give you $1070 (1000+ 0.07-1000) after one year and $1144.90 (1070+0.07-1007) after two years. However, because of inflation, that $1144.90 after two years is not worth the same as $1144.90 now. If the inflation rate is 2%, $1144.90 in two years is the equivalent of $1100.44 now-i.e- 102 More generally, the present value, p, of an investment is 1.02² 1144.90 f p= where is the inflation rate as a percentage. Typically, one would add to the investment with annual contributions. Let's say you start with a $1000 investment and add $100 every year. Therefore, after the first year, you will have $1177 - 7% return on $1100i.e. $1000 initial investment + the $100 year one contribution. After the second year, you will have $1366.39 - 7% return on $1277 - i.e. $1177 year one end + the $100 year two contribution. For 10 years, you will get the following: Year 0 1 2 3 4 5 6 7 8 9 10 (1+. ¹+100) Payment Future Value Present Value 1000.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 1177.00 1366.39 1569.04 1785.87 2017.88 2266.13 2531.76 2815.99 1153.92 1313.33 1478.54 1649.87 1827.66 2012.26 2204.05 2403.42 2610.76 2826.52 3120.10 3445.51 The present value is calculated from the future value using the above formula. Running the program Your program should take 5 arguments: start annual years return inflation where start is the initial investment amount annual is the amount that is added to the investment every year years is the number of years that the investment is held return is the annual investment return expressed as a percentage inflation is the annual inflation rate expressed as a percentage So, to calculate the future and present value of $1000 investment after 10 years where you add $100 every year with a 7% return and 2% inflation, you give the following arguments and get this output: $ ./fv 1000 100 10 7 2 Future Value: $3445.51 Present Value: $2826.52 Writing the code Starter code is provided for you below int main(int arge, char **argv ) { int a, n double value, present, I, is value= atof (argv[1]); a = atoi (argv[2]); natoi (argv[3]); r = atof (argv[4])/100; i = atof(argv[5])/100; // TODO write your code here printf("Future Value: $%.2f\n", value) printf("Present Value: $%.2f\n", present); I have provided code to input the 5 arguments using argy and also code to print the results. Do not change this code. The first three arguments are integers, but the last 2 arguments are floating-point arguments, so that's why I use the double type and the atof function instead of atoi. Remember that the investment return and inflation rates are expressed as percentages - that's the reason for the divide by 100. You will need to write a loop that iterates over the number of years and accumulates the future value. Make sure to add the annual contribution every loop iteration. Note that it is possible to calculate the future and present value with a single equation, but for this problem, you are required to do the calculations using a loop. Do not use any functions from the built-in math library. You will need to create a function to calculate the power function so that you can get the denominator of the present value formula.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a program that can calculate the future and present value of an investment given
various parameters.
When you calculate the future value of an investment, the more years you hold the
investment and the higher the rate of return, the more valuable it is. For example, a $1000
investment at 7% return will give you $1070 (1000+ 0.07-1000) after one year and
$1144.90 (1070+0.07-1007) after two years.
However, because of inflation, that $1144.90 after two years is not worth the same as
$1144.90 now. If the inflation rate is 2%, $1144.90 in two years is the equivalent of
$1100.44 now-i.e- 102 More generally, the present value, p, of an investment is
1.02²
1144.90
f
p=
where is the inflation rate as a percentage.
Typically, one would add to the investment with annual contributions. Let's say you start
with a $1000 investment and add $100 every year. Therefore, after the first year, you will
have $1177 - 7% return on $1100i.e. $1000 initial investment + the $100 year one
contribution. After the second year, you will have $1366.39 - 7% return on $1277 - i.e.
$1177 year one end + the $100 year two contribution. For 10 years, you will get the
following:
Year
0
1
2
3
4
5
6
7
8
9
10
(1+.
¹+100)
Payment Future Value Present Value
1000.00
100.00
100.00
100.00
100.00
100.00
100.00
100.00
100.00
100.00
100.00
1177.00
1366.39
1569.04
1785.87
2017.88
2266.13
2531.76
2815.99
1153.92
1313.33
1478.54
1649.87
1827.66
2012.26
2204.05
2403.42
2610.76
2826.52
3120.10
3445.51
The present value is calculated from the future value using the above formula.
Transcribed Image Text:Write a program that can calculate the future and present value of an investment given various parameters. When you calculate the future value of an investment, the more years you hold the investment and the higher the rate of return, the more valuable it is. For example, a $1000 investment at 7% return will give you $1070 (1000+ 0.07-1000) after one year and $1144.90 (1070+0.07-1007) after two years. However, because of inflation, that $1144.90 after two years is not worth the same as $1144.90 now. If the inflation rate is 2%, $1144.90 in two years is the equivalent of $1100.44 now-i.e- 102 More generally, the present value, p, of an investment is 1.02² 1144.90 f p= where is the inflation rate as a percentage. Typically, one would add to the investment with annual contributions. Let's say you start with a $1000 investment and add $100 every year. Therefore, after the first year, you will have $1177 - 7% return on $1100i.e. $1000 initial investment + the $100 year one contribution. After the second year, you will have $1366.39 - 7% return on $1277 - i.e. $1177 year one end + the $100 year two contribution. For 10 years, you will get the following: Year 0 1 2 3 4 5 6 7 8 9 10 (1+. ¹+100) Payment Future Value Present Value 1000.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 1177.00 1366.39 1569.04 1785.87 2017.88 2266.13 2531.76 2815.99 1153.92 1313.33 1478.54 1649.87 1827.66 2012.26 2204.05 2403.42 2610.76 2826.52 3120.10 3445.51 The present value is calculated from the future value using the above formula.
Running the program
Your program should take 5 arguments: start annual years return inflation
where
start is the initial investment amount
annual is the amount that is added to the investment every year
years is the number of years that the investment is held
return is the annual investment return expressed as a percentage
inflation is the annual inflation rate expressed as a percentage
So, to calculate the future and present value of $1000 investment after 10 years where you
add $100 every year with a 7% return and 2% inflation, you give the following arguments
and get this output:
$ ./fv 1000 100 10 7 2
Future Value: $3445.51
Present Value: $2826.52
Writing the code
Starter code is provided for you below
int main(int arge, char **argv )
{
int a, n
double value, present, I, is
value= atof (argv[1]);
a = atoi (argv[2]);
natoi (argv[3]);
r = atof (argv[4])/100;
i = atof(argv[5])/100;
// TODO write your code here
printf("Future Value: $%.2f\n", value)
printf("Present Value: $%.2f\n", present);
I have provided code to input the 5 arguments using argy and also code to print the results.
Do not change this code. The first three arguments are integers, but the last 2 arguments
are floating-point arguments, so that's why I use the double type and the atof function
instead of atoi. Remember that the investment return and inflation rates are expressed
as percentages - that's the reason for the divide by 100.
You will need to write a loop that iterates over the number of years and accumulates the
future value. Make sure to add the annual contribution every loop iteration. Note that it
is possible to calculate the future and present value with a single equation, but for this
problem, you are required to do the calculations using a loop.
Do not use any functions from the built-in math library. You will need to create a function
to calculate the power function so that you can get the denominator of the present value
formula.
Transcribed Image Text:Running the program Your program should take 5 arguments: start annual years return inflation where start is the initial investment amount annual is the amount that is added to the investment every year years is the number of years that the investment is held return is the annual investment return expressed as a percentage inflation is the annual inflation rate expressed as a percentage So, to calculate the future and present value of $1000 investment after 10 years where you add $100 every year with a 7% return and 2% inflation, you give the following arguments and get this output: $ ./fv 1000 100 10 7 2 Future Value: $3445.51 Present Value: $2826.52 Writing the code Starter code is provided for you below int main(int arge, char **argv ) { int a, n double value, present, I, is value= atof (argv[1]); a = atoi (argv[2]); natoi (argv[3]); r = atof (argv[4])/100; i = atof(argv[5])/100; // TODO write your code here printf("Future Value: $%.2f\n", value) printf("Present Value: $%.2f\n", present); I have provided code to input the 5 arguments using argy and also code to print the results. Do not change this code. The first three arguments are integers, but the last 2 arguments are floating-point arguments, so that's why I use the double type and the atof function instead of atoi. Remember that the investment return and inflation rates are expressed as percentages - that's the reason for the divide by 100. You will need to write a loop that iterates over the number of years and accumulates the future value. Make sure to add the annual contribution every loop iteration. Note that it is possible to calculate the future and present value with a single equation, but for this problem, you are required to do the calculations using a loop. Do not use any functions from the built-in math library. You will need to create a function to calculate the power function so that you can get the denominator of the present value formula.
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education