population increase program

Hey guys, hows it going.
I have a project im working on and I should know how to do this but I dont.
I have the bulk of the code working for the most part just need to make some little tweaks.
I have two questions:

1) I need to display population increase each day, I got it to display each day but the way I set my code up it displays only the one rate multiple times. Do I use an array? And could I see how that would be set up?
(in other words if you enter a starting pop of 10, a percent of 5, and 10 days it will just display 10.5 ten times rather than:
Day 1: 10.5
Day 2 : 11.025 etc...)

2) When someone enters less than a population of two it should pop with an error which it does, and asks the operator to enter again. How would I do that and continue running the program as right now it asks for the new input and exits the program?

Im sure there is a much nicer easier way of doing this but, this is what I have.
_______________________________________________

#include <iostream>
#include <cmath>
using namespace std;

main(){
int starting_population, size, days;
double rate_of_increase;
double new_pop;
double increase;
double percent;
cout << " Welcome! This program will predict population increase" << endl;
cout << " Enter the starting population size" << endl;
cin >> starting_population;
cout << "Enter expected rate of increase as a percentage" << endl;
cin >> rate_of_increase;
cout << "Enter number of days" << endl;
cin >> days;
while (starting_population < 2 || rate_of_increase < 0 || days < 1)
{
if(starting_population < 2){
cout << "Error. Please enter a starting population greater than two" << endl;
cin >> starting_population;
}
else if(rate_of_increase < 0){
cout << "Error. Please enter a percentage greater than 0" << endl;
cin >> rate_of_increase;
}
else if(days < 1){
cout << "Error. Please enter at least 1 day" << endl;
cin >> days;
}
}

percent = rate_of_increase/100;
increase = starting_population*percent;
new_pop = starting_population + increase;

for(int x = 0; x < days; x++){
cout << new_pop << endl;
}





return (0);
}
your calculation is outside your loop...

1
2
3
4
5
6
7
8
percent = rate_of_increase / 100;
new_pop = starting_pop;

for (int x = 0; x < days; x++){
	increase = new_pop*percent;
	new_pop += increase;
	cout << new_pop << endl;
}

thanks a bunch Jaybob
Topic archived. No new replies allowed.