fork download
  1. //Nathan Dominguez CSC5 Chapter 5, P. 296, #11
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Predict Population
  6.  * _____________________________________________________________________________
  7.  * This program updates the population of organisms based on starting number of
  8.  * organisms, the percent increase of population, and the amount of days given.
  9.  *
  10.  * Computation is based on the following:
  11.  * Total Population = Start Amount + Percent Increase of Population
  12.  * _____________________________________________________________________________
  13.  * INPUT
  14.  * Population : Starting number of population
  15.  * Percent Increase of Population : Increase of current population
  16.  * Days : Number of Days
  17.  *
  18.  * OUPUT
  19.  * Total Population : Total population of a given day
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. int population;
  27. float avgIncrease;
  28. int daysMultiply;
  29.  
  30. // Input starting population
  31. cout << "What is the starting number of organisms? " << endl;
  32. cin >> population; // input
  33.  
  34. // loop for population of days
  35. while (population < 2)
  36. {
  37. cout << endl << "You must have a starting size of 2 or more to continue." << endl << endl;
  38. cout << "What is the starting number of organisms?" << endl;
  39. cin >> population; // input
  40. }
  41.  
  42. // Input Percent Increase in Population
  43. cout << "What is their average daily population percentage increase? " << endl;
  44. cin >> avgIncrease; // input
  45.  
  46. // loop for percent increase of input population
  47. while (avgIncrease < 0)
  48. {
  49. cout << "The average increase cannot be a negative number." << endl << endl;
  50. cout << "What is their average daily population percentage increase? ";
  51. cin >> avgIncrease; // input
  52. }
  53.  
  54. // Input the amount of Days
  55. cout << "For how many days will they multiply? ";
  56. cin >> daysMultiply; // input
  57.  
  58. // loop for population increase each day
  59. while (daysMultiply < 1)
  60. {
  61. cout << endl << "The days must be greater than or equal to 1" << endl << endl;
  62. cout << "For how many days will they multiply? ";
  63. cin >> daysMultiply; // INPUT
  64. }
  65.  
  66. // Display and calculations of results for each day passed
  67. for (int display = 1; display <= daysMultiply; display++)
  68. {
  69. cout << endl << "Day " << display << endl; // output
  70.  
  71. population += (population * avgIncrease); // calculation
  72.  
  73. // output
  74. cout << "The population grew to " << population << " organisms." << endl;
  75. }
  76. return 0;
  77. }
Success #stdin #stdout 0.01s 5272KB
stdin
5
.2
5
stdout
What is the starting number of organisms? 
What is their average daily population percentage increase? 
For how many days will they multiply? 
Day 1
The population grew to 6 organisms.

Day 2
The population grew to 7 organisms.

Day 3
The population grew to 8 organisms.

Day 4
The population grew to 9 organisms.

Day 5
The population grew to 10 organisms.