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

Develop a code that calculates and prints data in designated formats. The annual

ID: 3580839 • Letter: D

Question

Develop a code that calculates and prints data in designated formats. The annual (or regular interval) payment w from a lump sum P with a compound interest r is referred to as annuity Assuming that the sum is completely withdrawn in n years, w, and the total of the payments W, in the ith year arc calculated by the formulas, w = p (r(1+r)^n-1/(1+r)^n-1) and W_i = i * P * r (1 + r)^n-1/((1 + r)^n - 1) where n is the number of years over which the annuity occurs. Write a C code that inputs the parameters P, r, and n, and calculates and outputs W_i for each year. In main Create a structure that contains the following information: name, social security #, Total_years, interest rate, Principal, float arrays W Let Total years be 5, Principal be 400000, interest rate be 5% Give a name and social security to the structure. Call function Annuity with structure as argument Print the data in the following formats. Save the above data to a file, "annuity data", using the above format. Function Annuity Take the structure from the above Write a loop to calculate W, and store it in the array of the structure.

Explanation / Answer

#include <stdio.h>
#include <string.h>

struct compoundInterest
{
   char socialSecurityNum[20];
   char name[20];
   int totalYears;
   float interestRate;
   float principal;
};

void calculate(struct compoundInterest record);

int main()
{
   char userName[20],ssn[20];
   float P,r,n;
   printf("Enter name: ");
   scanf("%s",userName);
   printf("Enter SSN Number: ");
   scanf("%s",ssn);
   printf("Enter P: ");
   scanf("%f",&P);
   printf("Enter n: ");
   scanf("%d",&n);
   printf("Enter r: ");
   scanf("%f",&r);
  
   struct compoundInterest record;

   strcpy(record.name, userName);
   strcpy(record.socialSecurityNum, ssn);
   record.years = n;
   record.interestRate = r;
   record.principal = P;

   calculate(record);
   return 0;
}

void calculate(struct compoundInterest record)
{
   int i;
   printf("Year Total Payment");
   for(i = 0;i< record.years;i++){
       record.principal = record.principal + (record.principal * record.interestRate) / 100;
       printf(" %d %f",(i+1),record.principal);
   }
}