0

Hello,
i have wrote a program using the while loop but it crashes whenever i run it
Basically, the goal of a program is to calculate the population of a town with constant 10% growth annually and then find how many years left.
here is my code (any help will be appreciated)

//Program1
// Chapter 5.4

#include<iostream>

using namespace std;

int const INITPOP = 900;
int const FINALPOP = 20000;

// prototype

int main()
{
	int peopleCount;
	float annualPerc = .1;
	float yearsLeft,
		  annualGrowth;

	

	peopleCount = INITPOP;
	while (peopleCount < FINALPOP)
	{
		 annualGrowth = annualPerc * INITPOP;
		 peopleCount = annualGrowth + INITPOP;
		 yearsLeft = FINALPOP / peopleCount;
		 peopleCount += peopleCount;
		 cout << peopleCount << yearsLeft << endl;
	}
	
	system("pause");
	return 0;
	
}
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by grisha83
0

try this:

while (peopleCount < FINALPOP)
	{
		 annualGrowth = annualPerc * INITPOP;
		 peopleCount += (int)annualGrowth; // + INITPOP;
		 yearsLeft = FINALPOP / (float)peopleCount;
		 // peopleCount += peopleCount;
		 cout << peopleCount << yearsLeft << endl;
	}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.