Solution to The population of town A is less than the population of town B. However, the … - Sikademy
Author Image

Archangel Macsika

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%.)

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question

using namespace std;


/*
	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%.)
*/


int main()
{
	float PopulationA=5000,PopulationB=8000;
	float Ra=4,Rb=2;
	float Pa,Pb;
	int n=1;
	
	cout<<"\n\tEnter Population   of Town A: "; cin>>PopulationA;
	cout<<"\n\tEnter Growtrh rate of Town A: "; cin>>Ra;
	cout<<"\n\tEnter Population   of Town B: "; cin>>PopulationB;
	cout<<"\n\tEnter Growtrh rate of Town B: "; cin>>Rb;
	Pa=PopulationA;
	Pb=PopulationB;
	
	while(Pa < Pb)
	{
		Pa = Pa + ((Pa*Ra)/100);
		Pb = Pb + ((Pb*Rb)/100);
		cout<<"\n\tAfter "<<n<<" years, Population of town A = "<<Pa<<", and Population of town B = "<<Pb;
		n=n+1;
	}
	cout<<"\n\n\tTherefore, after "<<n-1<<" years, population of town A will equal or exceed the population of town B.";
	return(0);
	
}

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1080-qpid-76