Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OK, I was able to get the above program to work and output all 4 years of growth

ID: 1927251 • Letter: O

Question

OK, I was able to get the above program to work and output all 4 years of growth.....but I am still getting an error about initializing my variable "year" and "total".....

Could someone take a look at my for loop to let me know where I forgot to initialize my two variables? Thanks, in advance, for your assistance.....

#include <iostream>
using namespace std;
int main()
{int popA,popB, loop, total, year;
double rateA,rateB;
int years=0;
cout<<"Enter population of Dogville: ";
cin>>popA;
cout<<"Enter growth rate of Dogville: ";
cin>>rateA;
cout<<"Enter population of Cattown: ";
cin>>popB;
cout<<"Enter growth rate of Cattown: ";
cin>>rateB;
rateA/=100.;
rateB/=100.;
cout<<"year Dogville Cattown ";

for (loop = 1; loop <= 4; loop++)
{
total += year;
}

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


#include <iostream>
using namespace std;
int main()


{

int popA,popB, loop, double rateA,rateB;


int years=0;

int total=0;


cout<<"Enter population of Dogville: ";
cin>>popA;
cout<<"Enter growth rate of Dogville: ";
cin>>rateA;
cout<<"Enter population of Cattown: ";
cin>>popB;
cout<<"Enter growth rate of Cattown: ";
cin>>rateB;
rateA/=100.;
rateB/=100.;
cout<<"year Dogville Cattown ";

for (loop = 1; loop <= 4; loop++)
{
total += year;
}

while(popA<popB)
{

popA=(int)(popA*rateA+popA);
popB=(int)(popB*rateB+popB);
years++;
cout<<years<<" "<<popA<<" "<<popB<<endl;
}

system("pause");
return 0;
}