Answer to Question #303307 in C++ for Becca

Question #303307

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:

  1. The population of town A
  2. The population of town B
  3. The growth rate of town A
  4. The growth rate of town B

The program outputs:

  1. After how many years the population of town A will be greater than or equal to the population of town B
  2. 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%.)


1
Expert's answer
2022-02-27T03:58:10-0500
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);
	
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog