array question

+1 Hayden Kuk · November 18, 2015

int main()
{
    int ir, year, i;
    float op = 100;
    float cir;
    int irArray[N];
    float cirArray[N];

    printf("This program calculates compound interest rate and \ntotal percentage depending on the initial interest rate.\n");
    printf("interest rate ranges from its initial rate up to +4%% \n");
    printf("Enter initial interest rate : ");
    scanf(" %d %%\n", &ir);
    printf("Enter number of years to invest : ");
    scanf(" %d \n", &year);

    printf("range of interest rate is : %d%% ~ %d%% \n", ir, (ir + 4) );
    printf("number of years to invest is : %d \n", year);
    ir -= 1;

    for(i = 0; i < N; i++)
    {
         ir++;
         irArray[i] = ir;
         printf("the interest rates are : %d %% \n", irArray[i]);
    };

for(i = 0; i < N; i++)
    {
        cir = op * (float)(1 + ( irArray[i] * 0.01));
        cir = cirArray[i];
        printf("compound rate is %d %% \n", cirArray[i]);
    };




    return 0;
}


in the last for loop, I would like to store cir value to cirArray in its corresponding i value's position,
since I plan to insert ir(interest rate) input in just integer(1..2.3..4), in order to get cir(106%.. 107%... etc), I reckon I need to multiply op(original percentage) by (1 + (ir * 0.01))
but when i run the program to print out cirArray in the last for loop, calculated compound interest rate is not proper as I planned.
why? 

Post a Reply

Replies

Oldest  Newest  Rating
0 kumar gaurav · November 18, 2015
In the Second statement of Last for Loop you should write  cirArray = cir ; NOT cir = cirArray;
0 kumar gaurav · November 22, 2015
cirArray  = cir ;    instead of   cir=cirArray ;
  • 1

C

107,106 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator