PDA

Click to See Complete Forum and Search --> : print


XOX
May 27th, 2001, 12:06 PM
i want to know how i can print the 3 first and the 3 last result to know how many years that will take before i hit 1000000. i can print the years like 1 2 3 22 23 24 but i can't print the value who correspond to the year, just the last one is printed, i don't know how to put the for in the while. here's the code


#include <stdio.h>
void main() {

float TAUX, DEPOSIT, interet, capital = 0, temp;
int i, years = 0, max = 1000000, FIRST = 3, LAST = 3;

printf("Entrez le depot et le taux d'interet\n");
scanf("%f%f", &DEPOSIT, &TAUX);

printf("years | Capital | interet | Interet + Capital\n");

TAUX = TAUX / 100;

while (capital <= max)
{
capital = capital + DEPOSIT;
temp = capital;
years += 1;
capital *= (1 + TAUX);
interet = capital - temp;
}
for ( i = 0; i < years; i++)
if (i < FIRST || i >= years - LAST)
{
printf("%3d)%13.2f%10.2f%12.2f\n", i + 1, temp, interet, capital);
}