Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //starting off
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main ()
- {
- //initializing variables for number of organisms given, average daily population increase, and number of days multiplying
- double startNumOrganisms;
- double aveDailyIncrease;
- double numDaysMult;
- //asking for the starting number of organisms
- cout << "Enter the starting number of organisms: ";
- cin >> startNumOrganisms;
- // asking for the average daily population increase percentage
- cout << "Enter the average daily population increase (as a percentage): ";
- cin >> aveDailyIncrease;
- // asking for the number of days they will multiply
- cout << "Enter the number of days they will multiply: ";
- cin >> numDaysMult;
- // each day given? yikes. Define "day"?
- //int day;
- // defining population size for the population size found on each day
- //int populationSize;
- // limiting what I will accept for cin
- // no startNumOrganisms under 2
- // if the bastards cin something wrong anyway, this is what I will display:
- if (startNumOrganisms <2)
- {
- cout << "The starting number of organisms must be at least 2.";
- cin >> startNumOrganisms;
- }
- // no population increase less than 0, also the display
- if (aveDailyIncrease <0)
- {
- cout << "The average daily population increase must be a positive value.";
- cin >> aveDailyIncrease;
- }
- //
- if (numDaysMult <1)
- {
- cout << "The number of days must be at least 1.";
- cin >> numDaysMult;
- }
- // setting up the loop: using FOR loop
- int populationSize = startNumOrganisms;
- for (int day = 1; day <= numDaysMult ; day++)
- {
- populationSize += populationSize * aveDailyIncrease;
- // round number by converting to int
- int rounded = populationSize;
- // displaying the answers for each day
- cout << "On day " << day << " the population size was " << rounded << ".\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement