This program is designed to analyze the growth of two cities. Each city has a st
ID: 3643947 • Letter: T
Question
This program is designed 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.This what I have so far but what happens if the user inputs a larger % on the bigger city?? How do I prevent that?
int main()
{
int popA,popB;
double rateA,rateB;
int years=0;
cout<<"Enter population of Pena: ";
cin>>popA;
cout<<"Enter growth rate of Pena: ";
cin>>rateA;
cout<<"Enter population of Jayleighville: ";
cin>>popB;
cout<<"Enter growth rate of Jayleighville: ";
cin>>rateB;
rateA/=100.;
rateB/=100.;
cout<<"year Pena Jayleighville ";
while(popA<popB)
{popA=(int)(popA*rateA+popA);
popB=(int)(popB*rateB+popB);
years++;
cout<<years<<" "<<popA<<" "<<popB<<endl;
}
system("pause");
return 0;
}
Explanation / Answer
You can use if else for specific ranges
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.