Trouble with looping

CLOSED
Last edited on
Include cstdlib if you want to use system(). In your population function, you're printing out the num_pop over and over again but you're not doing anything with it, which causes an endless loop. The number of population should change throughout the loop. Same goes for your other functions.
Thank you for the quick response. I'm very new to c++, how can i change num_pop and the like to NOT print over and over again?
You can just delete those three functions; they won't help you. In the main function, make a for loop that creates some variable that is equal to 1, and loops until that variable is less than or equal to num_days, incrementing x each loop. Inside the loop, use num_pop and grow_per in some kind of equation and print that out.

EDIT: I mean set num_pop equal to some equation using grow_per and print out num_pop each time. When you're done with that, you just need to add data validation using while loops.
Last edited on
I'm pretty sure i got it, does this look correct?

*edited the first post*

EDIT: I can't seem to get it to print the population increase after each day. It only prints the increase after one day. How can i fix this?
Last edited on
Replace that while loop at the end with a for loop like this:

 
for(int x = 1; x <= num_days; x++)


That's not really important, but you might as well. Your problem is that you're not changing the new_population in the loop, so new_population remains the same throughout the loop.

I need to go to sleep. You'll have to figure the rest out alone, or maybe someone else will help you.
Last edited on
Thanks for all the help!
bump - still can't seem to figure it out. I've tried re arranging where i put the calculations but i still can't figure out how to change my variable new_population inside of the loop. If anyone could explain a little further it'd be greatly appreciated. Thank you!
How can we answer a question when you delete the question?

And furthermore, why should we spend the time to answer a question if you're just going to delete it as soon as you get an answer?

Read this:
http://cplusplus.com/forum/articles/40179/
Topic archived. No new replies allowed.