Advertisement
Guest User

Project for Calculating Population size

a guest
Aug 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. // full program time!
  2. // predict the size of a population of organisms
  3. // cin starting number of organisms, average daily population increase (percentage in decimal form), number of days that they will multiply
  4. // loop used to display the size of the population for each day
  5.  
  6. // 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
  7. //do not accept daily population increase < 0, display "The average daily population increase must be a positive value."
  8. //do not accept number of days < 1, display "The number of days must be at least 1."
  9.  
  10. /* more verbage:
  11. 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.
  12. On day 2 the population size was 24.
  13. On day 3 the population size was 27.
  14. On day 4 the population size was 29.
  15. On day 5 the population size was 32.
  16. On day 6 the population size was 35.
  17. On day 7 the population size was 39.
  18. On day 8 the population size was 43.
  19. On day 9 the population size was 47. */
  20.  
  21. //always 20, 0.1, and 10?
  22.  
  23. //starting off
  24. #include <iostream>
  25. #include <cmath>
  26. using namespace std;
  27.  
  28. int main ()
  29. {
  30. //initializing variables for number of organisms given, average daily population increase, and number of days multiplying
  31. int startNumOrganisms;
  32. int aveDailyIncrease;
  33. int numDaysMult;
  34.  
  35. //asking for the starting number of organisms
  36. cout << "Enter the starting number of organisms: ";
  37. cin >> startNumOrganisms;
  38.  
  39. // asking for the average daily population increase percentage
  40. cout << "Enter the average daily population increase (as a percentage): ";
  41. cin >> aveDailyIncrease;
  42.  
  43. // asking for the number of days they will multiply
  44. cout << "Enter the number of days they will multiply: ";
  45. cin >> numDaysMult;
  46.  
  47. // each day given? yikes. Define "day"?
  48. int day;
  49.  
  50. // defining population size for the population size found on each day
  51. int populationSize;
  52.  
  53. // limiting what I will accept for cin
  54.  
  55. // no startNumOrganisms under 2
  56. // if the bastards cin something wrong anyway, this is what I will display:
  57. if (startNumOrganisms <2)
  58. {
  59. cout << "The starting number of organisms must be at least 2.";
  60. }
  61.  
  62. // no population increase less than 0, also the display
  63. if (aveDailyIncrease <0)
  64. {
  65. cout << "The average daily population increase must be a positive value.";
  66. }
  67.  
  68. //
  69. if (numDaysMult < 1)
  70. {
  71. cout << "The number of days must be at least 1.";
  72. }
  73. // setting up the loop: using FOR loop
  74. for (day = 1; day >= numDaysMult && day <= numDaysMult ; day++)
  75. {
  76. // calulating populationSize---> algebra: startNumOrganisms + (startNumOrganisms * aveDailyIncrease * day) = populationSize
  77. populationSize = startNumOrganisms * (day* startNumOrganisms * aveDailyIncrease);
  78.  
  79. // displaying the answers for each day
  80. cout << "On day " << day << "the population size was " <<populationSize <<". \n";
  81.  
  82. }
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement