### Code taking a lot of time but no result

OK so there is this question:
 The country A has 50M inhabitants, and its population grows 3% per year. The country B, 70M and grows 2% per year. Tell in how many years A will surpass B.

And the heading specifies my problem.

Finally here is my code (yes it is C):
 ``12345678910111213141516171819202122232425`` ``````#include int main() { const int A_GROWTH_RATE = 3; const int B_GROWTH_RATE = 2; const int A_POPULATION = 50; //MILS const int B_POPULATION = 70; //MILS float a_pop_curr = A_POPULATION; float b_pop_curr = B_POPULATION; int years = 0; while(a_pop_curr <= b_pop_curr) { a_pop_curr += a_pop_curr*(A_GROWTH_RATE/100); b_pop_curr += b_pop_curr*(B_GROWTH_RATE/100); years++; } printf("After %d years, A will have a population of %.2f while B will have a population of %.2f", years, a_pop_curr, b_pop_curr); return 0; }``````
Last edited on
Integer division

These resolve to 0.
`(A_GROWTH_RATE/100);` = 0
`(B_GROWTH_RATE/100);` = 0

Last edited on
OK I changed those lines and now it works! Thanks :D!
 ``12`` ``````a_pop_curr += a_pop_curr*(A_GROWTH_RATE/100.0); b_pop_curr += b_pop_curr*(B_GROWTH_RATE/100.0);``````
Topic archived. No new replies allowed.