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 program outputs:
(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%.)
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);
}
Comments
Leave a comment