fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 4
  2. //
  3. /**************************************************************
  4.  * CALCULATE ANNUAL POPULATION
  5.  *
  6.  * ____________________________________________________________
  7.  * This program will calculate the annual population per year.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * population : starting pupolation
  11.  * birth : birth rate
  12.  * death : death rate;
  13.  * years : the number of years
  14.  * OUTPUT
  15.  * newyear : new population
  16.  **************************************************************/
  17. #include <iostream>
  18. #include <iomanip>
  19. #include <cmath>
  20. using namespace std;
  21. float newyear();
  22.  
  23.  
  24. int main()
  25. {
  26.  
  27. newyear();
  28. return 0;
  29.  
  30. }
  31. float newyear()
  32. {
  33.  
  34. // N = P + BP - DP
  35. float newyear,
  36. population,
  37. birth,
  38. death,
  39. years;
  40. cout<<"How many years do you want to calculate?"<<endl;
  41. cin>>years;
  42. while (years<0)
  43. {
  44. cout<<"please enter a vaild number"<<endl;
  45. cin>> years;
  46. }
  47. cout<<"whats the starting population?"<<endl;
  48. cin>>population;
  49. while (population<2)
  50. {
  51. cout<<"please enter a vaild number"<<endl;
  52. cin>> population;
  53. }
  54. cout<<"whats the birth rate?"<<endl;
  55. cin>> birth;
  56. while (birth<0)
  57. {
  58. cout<<"please enter a vaild number"<<endl;
  59. cin>> birth;
  60. }
  61. cout<<"whats the death rate?"<<endl;
  62. cin>> death;
  63. while (death<0)
  64. {
  65. cout<<"please enter a vaild number"<<endl;
  66. cin>> death;
  67. }
  68. for (int i = 1; i <= years; i++)
  69. {
  70. birth=(birth/100)*population;
  71. death=(death/100)*population;
  72. newyear = population + birth - death;
  73. population = newyear;
  74. cout<<"the population in year "<<i<<" is "<<newyear<<endl;
  75. }
  76. return newyear;
  77.  
  78.  
  79.  
  80. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty