Need help on this school assignment on for loop

This is a discussion on Need help on this school assignment on for loop within the C Programming forums, part of the General Programming Boards category; This is what its suppose to look like for the output: -------------------------------------------------------------------------- Year Value Interest Payment Amt Retired 1 100000.00 ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    2

    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;

    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ code for school assignment
    By Pupo in forum C++ Programming
    Replies: 3
    Last Post: 03-09-2010, 08:11 AM
  2. Help for school assignment
    By Allynia in forum C Programming
    Replies: 9
    Last Post: 04-29-2008, 04:07 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Replies: 1
    Last Post: 10-27-2006, 02:21 PM
  5. stupid school assignment
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-20-2003, 10:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21