Whats wrong with my code ?

So I am supposed to write a code where the user inputs the population and growth rate in percentage/year of two towns A and B. I need to find out how many years it would take town A to have a greater population than town B. I am running my code and inputting (5000 4) for town A and (8000 2) for town B but the program stops. Any idea why?

#include <iostream>
using namespace std;

int main()
{
double popA, popB;
int growthA, growthB, years = 0;

cout << "Enter the population and growth rate of A: ";
cin >> popA >> growthA;

cout << "Enter the population and growth rate of B: ";
cin >> popB >> growthB;

while(popA<popB)
{
popA = popA + (growthA/100 * popA);
popB = popB + (growthB/100 * popB);
years++;
}

cout << "After " << years << " years the population of A will be greater than the population of B." << endl;
cout << "The population of A is: " << popA << endl;
cout << "The population of B is: " << popB << endl;

return 0;
}
The growth* are int. The 100 is an int. int/int is integer division. Integer division discards fraction. 99/100 is still 0.

It is enough for one of the operands to be a floating point value to avoid integer division.
For example, growth/100.0 or (popA*growthA)/100


PS. Please use code tags when posting code.
Im sorry, this is my first post here, I did not know about the code tags.

Thank you so much however... I didnt think something like this would mess up the whole code.
Registered users can post here. Sign in or register to post.