# Need help on this school assignment on for loop

• 12-01-2010
spyropyro
Need help on this school assignment on for loop
This is what its suppose to look like for the output:
--------------------------------------------------------------------------
Year Value Interest Payment Amt Retired
1 100000.00 6000.00 13586.80 8000.00
2 92000.00 5520.00 13526.05 8000.00
3 84000.00 5040.00 13527.03 8000.00
.
.
.
10 13000.00 780.00 13780.01 13000.00
--------------------------------------------------------------------------
=====Enter values are 100bonds, \$1000 each, 6% interestRate and 10 years

value = bond * bondprice

P = value*R/(1-(1/(1+R)^N)) R = rate of interest
N = number of years left
P = 13586.80

interest = R * value =.06 * 100000 = 6000
Number Retired = nearest integer of (P-interest)/bondprice
= nearest integer (7586.80/1000) = 8

I need help on the for loop calculations because after i run the for loop in main the number wouldnt come out right. I needs some help on how to fix this could anyone help
me?

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int input(float*, int*, float*);
float calculation(float, int, float, int, float*, float*, int, float*);

float subCalculation(float, float, float);

int main(void)
{ // variable declaration
float bondPrice;
int initBond;
float intRate;
int numYear;
float value;
float annualPay;
float amtRetired;
float interest;
int N;

N = 0;

//function call to input
numYear = input(&bondPrice, &initBond, &intRate);
printf("YEAR VALUE INTEREST PAYMENT AMT RETIRED\n");
for(N = 0; numYear - N >= 0; N++)
{
annualPay = calculation(bondPrice, initBond, intRate, numYear, &value, &interest, N, &amtRetired);
printf("%d %8.2f %8.2f %8.2f %8.2f\n", N, value, interest, annualPay, amtRetired * bondPrice);
}

system("PAUSE");
return 0;
}
//main
////////////////////////////////////////////////////////////////////////////////
int input(float* price, int* bond, float* interestRate)
{
// variable declaration
int years;
//prompt user input for all listed in function "Pre"
printf("Please enter price per bond: ");
scanf("%f", price);
printf("\nPlease enter the initial number of bonds: ");
scanf("%d", bond);
printf("\nPlease enter the interest rate: ");
scanf("%f", interestRate);
printf("\nPlease enter the number of years the debt is to be paid: ");
scanf("%d", &years);
//return years
return years;
}
//input
////////////////////////////////////////////////////////////////////////////////
float calculation(float price, int bond, float interestRate, int years, float* value,
float* interest, int N, float* amtRetired)
{ // variable declaration
int r;

float payment;
//calculate value of bond
*value = (float)price * bond;
*interest = (float)(interestRate/100) * *value;

payment = (*value * (interestRate/100))/(1 -(1/pow(1 + (interestRate/100), years - N)));

*amtRetired = subCalculation(price, payment, *interest);

// return payment
return payment;
}
//calculations
////////////////////////////////////////////////////////////////////////////////
float subCalculation(float price, float payment, float interest)
{ // variable declaration

float amtRetired;
amtRetired = (payment - interest)/(price);

amtRetired = floor(amtRetired +.5);

return amtRetired;

}
• 12-01-2010
Bayint Naung