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;
}
}