Hello all!
I'm self learning C and I am supposed to be creating a table with compounding interest for 5 years and for 5 levels of interest rates. I've been following an eBook and have been stuck on this Array area for a bit just trying to get my head around it.
The code I've got below just shows values of '100.00' for each "cell". Could someone please point out as to why this is?
It's most likely a really beginner/noob question, but either I just don't fully have my head around it yet or I'm too close to the task. Anyway, my code is below.
EDIT: Initial investment = $100.
Code:
#include <stdio.h>
#define NUM_RATES ((int) (sizeof(value) / sizeof(value[0])))
#define INITIAL 100
int main(void)
{
int i, rate, year, num_years;
double value[5];
printf("Enter interest rate [%%]: ");
scanf("%d", &rate);
printf("Enter number of years: ");
scanf("%d", &num_years);
printf("\nYears");
for (i = 0; i < NUM_RATES; i++){
printf("%6d%%", rate + i);
value[i] = INITIAL;
}
printf("\n");
for (year = 1; year <= num_years; year++){
printf("%3d ", year);
for (i = 0; i < NUM_RATES; i++){
value[i] += (rate + i) / 100 * value[i];
printf("%7.2f", value[i]);
}
printf("\n");
}
return 0;
}