Original Post
void mysociety(){
cout << "Here is the current state of your society: \n\n";
//display current statistics
cout << "The current population of your society is " << initpop << " humanoids." << endl;
//user action
cout << "\nEnter '1' if you would like to skip a number of years, '2' if you would like \nfurther information about your society or any other number if you would like to make changes to your society: ";
int skiporchange;
cin >> skiporchange;
if(skiporchange == 1)timestepforward();
else if(skiporchange == 2)aboutyoursociety();
else changes();}When I press '1' the timestepforward function is called. Its code is as follows:
void timestepfoward(){
otherfactors();
cout << "\n\nIt is currently year " << currentyear << " and the population is " << initpop << ".\n";
cout << "How many years would you like to skip? ";
cin >> t;
population();
currentyear = t+currentyear;
cout << "\nIt is now year " << currentyear << " and the population is now " << newpopulation << ".\n";
newpopulation=initpop;
mysociety();
}
void population(){
popgrowth=(births-deaths)/initpop+1;
newpopulation = initpop*exp( (births-deaths)/initpop * t );
}My problem is that when I call the first function after doing a time step forward, (mysociety()), the global variable for initpop has not updated! Why is this?