Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do i write a c++ program to analyze the growth of two cities Each city has a

ID: 3628824 • Letter: H

Question

how do i write a c++ program to analyze the growth of two cities Each city has a starting population and annual growth rate. The smaller city has the larger growth rate (required). Show the comparative populations of each city year by year until the smaller city has grown larger than the bigger city.

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown has a population of 7000 growing at 10% annually. The projected populations are:
Year Dogville Cattown
1 6000 7700
2 7200 8470
3 8640 9317
4 10368 10249

Explanation / Answer

#include <iostream>
using namespace std;
int main()
{int popuX,popuY;
double rateX,rateY;
int years=0;
cout<<"Enter the population of Dogville: ";
cin>>popuX;
cout<<"Enter the population of Cattown: ";
cin>>popuY;
cout<<"Enter the growth rate of Dogville: ";
cin>>rateX;
cout<<"Enter the growth rate of Cattown: ";
cin>>rateY;

rateX=rateX/100.;
rateY=rateY/100.;
cout<<"year Dogville Cattown ";

while(popuX<popuY)
    {popuX=(int)(popuX*rateX+popuX);
     popuY=(int)(popuY*rateY+popuY);
     years++;
     cout<<years<<" "<<popuX<<" "<<popuY<<endl;
    }

system("pause");
return 0;
}