Question: Do problem 16 in section 3.9 of the text (but DO NOT use the hint given there). Copy your account.c file from your Lab4 directory
Do problem 16 in section 3.9 of the text (but DO NOT use the hint given there). Copy your account.c file from your Lab4 directory into your Lab5 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 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.
Code I have so far:
float calc_acc_amt(float acc_amount, float annual_interest, int years);
#include
//Main function
int main()
{
//Declare variables
float acc_amount, interest, total;
int years;
//Ask for starting amount
printf(" What is your starting amount?: $");
scanf("%f", &acc_amount);
//Ask for annual interest rate
printf("What is the annual interest rate (in decimal format)?: ");
scanf("%f", &interest);
//Ask for number of years investing
printf("How many years did you want to keet investing?");
scanf("%d", &years);
//Call 'calculate interest function'
total = calc_acc_amt (acc_amount, interest, years);
//Display the value of investment
printf(" Your investment in %d years is $%7.2f ", years, total);
}
//Calculate interest function
float calc_acc_amt(float acc_amount, float annual_interest, int years)
{
//Declare variables
int starting_year = 0;
//Initialize while loop
while (starting_year < years)
{
//Calculate interest
acc_amount = acc_amount + acc_amount * annual_interest;
//Increment the year
starting_year++;
}
//Return the investment value
return acc_amount;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
