The population of town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. Write a program that prompts the user to enter: The population of town A The population of town B The growth rate of town A The growth rate of town B The program outputs: After how many years the population of town A will be greater than or equal to the population of town B The populations of both the towns at that time. (A sample input is: Population of town A = 5,000, growth rate of town A = 4%, population of town B = 8,000, and growth rate of town B = 2%.)

Respuesta :

Answer:

#include<iostream>

using namespace std;

void main()

{

int townA_pop,townB_pop,count_years=1;

double rateA,rateB;

cout<<"please enter the population of town A"<<endl;

cin>>townA_pop;

cout<<"please enter the population of town B"<<endl;

cin>>townB_pop;

cout<<"please enter the grothw rate of town A"<<endl;

cin>>rateA;

cout<<"please enter the grothw rate of town B"<<endl;

cin>>rateB;

while(townA_pop < townB_pop)//IF town A pop is equal or greater than town B it will break

{

townA_pop = townA_pop +( townA_pop * (rateA /100) );

townB_pop = townB_pop +( townB_pop * (rateB /100) );

count_years++;

}

cout<<"after "<<count_years<<" of years the pop of town A will be graeter than or equal To the pop of town B"<<endl;

}

Explanation: