Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming in \"C\" language Write a program that prints the accumulated value

ID: 642106 • Letter: P

Question

Programming in "C" language

Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:

Use a function that returns the accumulated value given the amount, interest, and years. The prototype is:

Modify the function in Problem above so that the interest may be compounded annually, monthly, or daily. Assume 365 days in the year. If interest is not to be compounded annually, the annual interest must be converted to monthly (i.e., interest / 12) or daily interest (i.e., interest / 365). The interest must then be compounded each year, each month, or each day as the case may be.

Instead of using the hint given in the text, if you think about this one for a minute, you can do it WITHOUT modifying the function you wrote for Lab4. (Hint: the trick is how you get the values you pass to the function calc_acc_amt(). Think about what the MEANING of the parameters are). However, you should write a new main() function which should repeatedly prompt the user to enter the data as before, and also prompt for either annual, monthly or daily compounding. This should be entered as an integer - 1 for annual, 2 for monthly, and 3 for daily. The program should continue getting data sets until the user enters end of file instead of the initial investment. Use simple macros in this program to avoid any "magic numbers" in your code.

Explanation / Answer

/* program to calculate compound interest */

/* the formula to calculate daily will be r/365 and n/365 if monthly r will be r/12 and n will be n/12 */

/*exp is a function available in math.h to raise a given value to a particular power)

#include

# include

Float p,n,r, p1,n1,r1;

Float calc_acc_amt(float acc_amount, float annual_interest, int years)

{

     Float finalamt ;

   Finalamt = acc_amount * exp( ( 1 + (annual_interest/100)) , years);

Printf(