Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

From Problem 15 and 16 of Section 3.9 of the online text on the website: Modify the function in this problem below so that the

From Problem 15 and 16 of Section 3.9 of the online text on the website: Modify the function in this problem below 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.
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:
acc_amount = acc_amount + acc_amount * annual_interest
Use a function that returns the accumulated value given the amount, interest, and years. The prototype is:
float calc_acc_amt(float acc_amount, float annual_interest, int years);
Copy your account.c file from your lab3 directory into your lab4 directory. 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 Lab3. (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. The EOF command should only need to be entered once, during the investment amount input, and quit immediately. Use simple macros in this program to avoid any "mystery numbers" in your code. Ask for inputs in the order of the example below. Do not print out each intermediate compounding step. Daily compounding will print way too much to the screen.
Example input is: Enter amount, interest rate, years: 1000 0.05 3
Enter compounding frequency (1 for annual, 2 for monthly, 3 for daily): 2
****Can you please help me modify the code below to fit the assignment
# include
float calc_acc_amt(float acc_amount, float annual_interest, int years);
float calc_acc_amt(float acc_amount, float annual_interest, int years)
{
int year;
float accumulated_amount = acc_amount;
for(year =1; year <=years; year++)
{
accumulated_amount+= accumulated_amount*annual_interest;
}
return accumulated_amount;
}
int main(){
float acc_amount =0.0, ann_interest =0.0;
int years =0;
printf("Enter the initial amount: ");
scanf("%f", &acc_amount);
if (acc_amount <= 0)
{
printf("Exit Program ");
return (0);
}
printf("Enter the annual interest rate (in decimal): ");
scanf("%f", &ann_interest);
printf("Enter the number of years: ");
scanf("%d" , &years);
float accumulated_amount = calc_acc_amt(acc_amount,ann_interest,years);
printf("Total Accumulated Amount : $%.2f ", accumulated_amount);
return(main());
}
thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

List the various reconciliation responses to conflict.

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago