Write a C++ program that reads the population of

town A and its growth rate as well as the
population of town B and its growth rate. It
outputs after how many years the population of
town A will be greater than that of town B and the
values of their population at that time.

Here's a sample pseudocode.

Input initial populations, p1, p2.
Input growth rates, r1,r2.
Input number of years to print, n.
for year=0 to n
output year, p1*pow(1+r1,year), p2*pow(1+r2,year)
next year

If you have problems getting your code to work, post your code.

Certainly! Here's a C++ program that reads the population of town A and its growth rate, the population of town B and its growth rate, and outputs the number of years it will take for town A's population to exceed that of town B, along with the populations of both towns at that time:

```c++
#include <iostream>

int main() {
int populationA, populationB;
double growthRateA, growthRateB;

// Read the population and growth rate of town A
std::cout << "Enter the population of town A: ";
std::cin >> populationA;
std::cout << "Enter the growth rate of town A (in percentage): ";
std::cin >> growthRateA;

// Read the population and growth rate of town B
std::cout << "Enter the population of town B: ";
std::cin >> populationB;
std::cout << "Enter the growth rate of town B (in percentage): ";
std::cin >> growthRateB;

int years = 0;

while (populationA <= populationB) {
// Update population based on growth rates
populationA += (populationA * growthRateA) / 100;
populationB += (populationB * growthRateB) / 100;

years++;
}

std::cout << "After " << years << " years, the population of town A (" << populationA
<< ") will be greater than that of town B (" << populationB << ")." << std::endl;

return 0;
}
```

To run this program, you can follow these steps:

1. Open a C++ compiler or integrated development environment (IDE) such as Code::Blocks, Visual Studio, or Xcode.
2. Create a new C++ source file.
3. Copy the above code into the source file.
4. Build and run the program.

You will be prompted to enter the population and growth rate for town A and town B. After inputting these values, the program will calculate the number of years it takes for town A's population to exceed that of town B, and it will display the populations of both towns at that time.