int main()
{
Population Town;
int People;
int Births,
Deaths;
cout << "Enter total population: ";
cin >> People;
while (People < 1)
{ cout << "ERROR: Value has to be greater than 0. ";
cin >> People;
}
Town.setPopulation(People);
cout << "Enter annual number of births: ";
cin >> Births;
while (Births < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Births;
}
Town.setBirths(Births);
cout << "Enter annual number of deaths: ";
cin >> Deaths;
while (Deaths < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Deaths;
}
Town.setDeaths(Deaths);
So what exactly are the errors you are getting that you are confused on? Also, please use code tags around your code either edit and click the <> button or type [code] before and [ /code] after(without space)
I am not sure what the Populate(): pop(0), deaths(0), births(0) {} is doing at the end of your class, but to start, every class should have a constructor and a method to set your variables as passable arguments, or else using them in those other functions will not do you any good.
As giblit said, please explain what the errors are (and code tags are your friends).
that is called an initializer list. That is also how you can initialize members that are constant or references.
Hmm. You learn something new every day I suppose. Personally, I would rather use a separate method to make it as explicit as possible, but I guess its preference. The constructor is still lacking...
Running it makes it look perfectly fine. As for initializer lists, they are generally preferred over explicit initialization due to both efficiency and flexibility (for example, you can have a class type variable in your class with a non-default constructor).