Problem in the algorithm on percentage

0

I had to do this algorithm:

  

In 2010, a small Brazilian city has 20,000 inhabitants. The forecast   of IBGE is that this city grows at a rate of 5% per year. Knowing   addition, make an algorithm that prints on the screen the year and population   planned for the city in such a year, with the year varying from 2011 to 2030.

using the for and I did this algorithm:

float populacao;
int conta,taxa,total;

populacao=20.000;
taxa=1.05;
for (conta=2011;conta<=2030;conta++)
{
    total=populacao*taxa;
    populacao=total;

    printf("O ano de %d tera %f de habitantes \n",conta,populacao);
}

But the result of the population is giving 20.000000 to all the years, what is wrong?

    
asked by anonymous 30.01.2018 / 00:06

1 answer

4

Your rate and total are set to int , but it is float . Change that and your algorithm will be working perfectly.

float populacao,taxa,total;
int conta;

populacao=20.000;
taxa=1.05;
for (conta=2011;conta<=2030;conta++)
{
    total=populacao*taxa;
    populacao=total;

    printf("O ano de %d tera %f de habitantes \n",conta,populacao);
}
    
30.01.2018 / 00:09