SoundSports in ear he x a Track Package x Shopping cart x Bb Upload Assi As x C
ID: 3778286 • Letter: S
Question
SoundSports in ear he x a Track Package x Shopping cart x Bb Upload Assi As x C Chegg How Assign6.pdf dy Guid C https:// g.utd bdav/pid 1334051-d d- 13560233 Assignments 6/Assign6.pd Apps LH S2tolE Google Do New Tab b Music's Top 40 M N 5 40IH D I D e Tren: DE] oloE ER Free Website Builder use Lewisville depend D YouTub Exercise 2 (50 points): Write a program that calculates the amount of money that you must invest in a savings account at a given interest rate for a given number of years to have a certain dollar amount at the end of the period. Your program will ask the user for the amount the user wants to have at the end of the term (future value), the number of years the user plans to let the money stay in the account, and the annual interest rate. The program will calculate the amount of money that the user needs to deposit (present value). Use the following formula to calculate the present value 1 t 100 P is the present value, or the amount of money deposited F is the future value that the user wants to have at the end r is the annual interest rate n is the number of years that the user plans to let the money stay in the account Your program must contain/use the following functions: getFuture Value A function that gets a nonnegative future value from the user getAnnualintRate -A function that gets a nonnegative annual interest rate from the user getYears-A function that gets the nonnegative number of years of the investment from the user calcPresentValue-A function that calculates and returns the amount that must be deposited given the future value, annual interest rate, and number of years as arguments e Co A Other bookmarks 11:54 PM 11/27/2016Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double getFutureValue()
{
double fValue;
printf("What is the desired future value of the account? ");
scanf("%lf",&fValue);
if(fValue<0)
{
printf("this value should be positve ");
exit(0);
}
return fValue;
}
double getAnnualIntRate()
{
double annInterestR;
printf("Enter the annual interest rate [For 1.1 enter 1.1]: " );
scanf("%lf",&annInterestR);
if(annInterestR<0)
{
printf("this value should be positve ");
exit(0);
}
return annInterestR;
}
int getYears()
{
int year;
printf("Enter the number of years the money will staty in the account: ");
scanf("%d",&year);
if(year<0)
{
printf("this value should be positve ");
exit(0);
}
return year;
}
double calcPresentValue(double futureValue,double rate,int years)
{
double temp=1+(float)rate/100;
double calcPValue=futureValue/pow(temp,years);
printf("You need to deposit %.2lf ",calcPValue);
}
int main()
{
double futureValue=getFutureValue();
double rate= getAnnualIntRate();
int years=getYears();
calcPresentValue(futureValue,rate,years);
return 0;
}
/*
output:-
What is the desired future value of the account? 25000
Enter the annual interest rate [For 1.1 enter 1.1]: 1.05
Enter the number of years the money will staty in the account: 18
You need to deposit 20715.08
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.