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: 641882 • 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.

Explanation / Answer

#include <stdio.h>

float calc_acc_amt(float acc_amount, float annual_interest, int years);
float modified_calc_acc_amt(float acc_amount, float annual_interest, int years, int option);

int main(){
   float amount, interest;
   int years;
   printf("Enter account amount: ");
   scanf("%f", &amount);
   printf("Enter annual interest: ");
   scanf("%f", &interest);
   printf("Enter Number of years: ");
   scanf("%d", &years);
   printf("Total amount after %d years(accumulated annually) is %.2f ", years, modified_calc_acc_amt(amount, interest, years, 0));
   printf("Total amount after %d years(accumulated monthly) is %.2f ", years, modified_calc_acc_amt(amount, interest, years, 2));
   printf("Total amount after %d years(accumulated daily) is %.2f ", years, modified_calc_acc_amt(amount, interest, years, 3));
   return 0;
}

float calc_acc_amt(float acc_amount, float annual_interest, int years){
   int i = 0;
   annual_interest = annual_interest / 100;
   for(i = 0; i < years; ++i){
       acc_amount = acc_amount + acc_amount * annual_interest;
   }
   return acc_amount;
}

// option = 1 for yearly accumulation
// option = 2 for monthly accumulation
// option = 3 for daily accumulation
float modified_calc_acc_amt(float acc_amount, float annual_interest, int years, int option){
   annual_interest = annual_interest / 100;
   if(option == 2){
       years = years * 12;
       annual_interest = annual_interest / 12;
   }
   else if(option == 3){
       years = years * 365;
       annual_interest = annual_interest / 365;
   }
   printf("%d, %.5f ", years, annual_interest);
   int i = 0;
   for(i = 0; i < years; ++i){
       acc_amount = acc_amount + acc_amount * annual_interest;
   }
   return acc_amount;
}