Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // full program time!
- // predict the size of a population of organisms
- // cin starting number of organisms, average daily population increase (percentage in decimal form), number of days that they will multiply
- // loop used to display the size of the population for each day
- // do not accept size of population <2, if user does anyway, display "The starting number of organisms must be at least 2.", display prompt again
- //do not accept daily population increase < 0, display "The average daily population increase must be a positive value."
- //do not accept number of days < 1, display "The number of days must be at least 1."
- /* more verbage:
- Enter the starting number of organisms: Enter the average daily population increase (as a percentage): Enter the number of days they will multiply: On day 1 the population size was 22.
- On day 2 the population size was 24.
- On day 3 the population size was 27.
- On day 4 the population size was 29.
- On day 5 the population size was 32.
- On day 6 the population size was 35.
- On day 7 the population size was 39.
- On day 8 the population size was 43.
- On day 9 the population size was 47. */
- //always 20, 0.1, and 10?
- //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
- int startNumOrganisms;
- int aveDailyIncrease;
- int 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.";
- }
- // no population increase less than 0, also the display
- if (aveDailyIncrease <0)
- {
- cout << "The average daily population increase must be a positive value.";
- }
- //
- if (numDaysMult < 1)
- {
- cout << "The number of days must be at least 1.";
- }
- // setting up the loop: using FOR loop
- for (day = 1; day >= numDaysMult && day <= numDaysMult ; day++)
- {
- // calulating populationSize---> algebra: startNumOrganisms + (startNumOrganisms * aveDailyIncrease * day) = populationSize
- populationSize = startNumOrganisms * (day* startNumOrganisms * aveDailyIncrease);
- // displaying the answers for each day
- cout << "On day " << day << "the population size was " <<populationSize <<". \n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement