fork download
  1. //Cecilia Rangel CSC5 Chapter 6, P.373, #15
  2. //
  3. /**************************************************************
  4.  *
  5.  * CALCULATE POPULATION SIZE
  6.  * ____________________________________________________________
  7.  * This program will ask for the user to input a positive
  8.  * number, and the program determines if the number is a prime
  9.  * number
  10.  *
  11.  *_____________________________________________________________
  12.  * INPUT
  13.  * population : size of population
  14.  * years : Number of years to display.
  15.  * Birth : Annual birth rate.
  16.  * Death : Annual death rate.
  17.  * OUTPUT
  18.  * new : New population size.
  19.  *
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. int calculatePopulation(int popSize, int birthRate, int deathRate);
  27.  
  28. int main() {
  29. int popSize;
  30. int birthRate;
  31. int deathRate;
  32. int years;
  33. int newPop;
  34.  
  35. cout << "What is the starting size of a population? ";
  36. cin >> popSize;
  37. if (popSize < 2) {
  38. cout << "Please choose a bigger number for the starting size.";
  39. }
  40. cout << "What is the annual birth rate? ";
  41. cin >> birthRate;
  42. if (birthRate < 0) {
  43. cout << "Please do not choose negative integers.";
  44. }
  45. cout << "What is the annual death rate? ";
  46. cin >> deathRate;
  47. if (deathRate < 0) {
  48. cout << "Please do not choose negative integers.";
  49. }
  50. cout << "What year is it? ";
  51. cin >> years;
  52. if (years < 1) {
  53. cout << "Please do not go lower than 1.";
  54. }
  55.  
  56. newPop = calculatePopulation(popSize, birthRate, deathRate);
  57.  
  58. cout << "This is the new population size " << newPop << " new humans in this world in the year " << years;
  59.  
  60.  
  61.  
  62. return 0;
  63. }
  64.  
  65. //Calculating the new world population with taking the inputs from main
  66.  
  67. int calculatePopulation(int popSize, int birthRate, int deathRate) {
  68. return (popSize + (birthRate * popSize) - (deathRate * popSize));
  69. }
  70.  
Success #stdin #stdout 0s 5320KB
stdin
10
5
6
2411
stdout
What is the starting size of a population? What is the annual birth rate? What is the annual death rate? What year is it? This is the new population size 0 new humans in this world in the year 2411