Skip to content

Commit

Permalink
Exercise 4.38
Browse files Browse the repository at this point in the history
  • Loading branch information
PureJoyMind committed Jul 10, 2021
1 parent b439e3f commit 8842b45
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ch.04/worldPopulationGrowth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Deitel ch.04 exercise 4.38
// accoring to "www.worldometers.info" the current
// world population is %1.05
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
// declaring current year
float currentYear{2020};
// declaring the growth rate
float rate{1.05};

// setting floating point precision
cout << setprecision(3)<<fixed;

// printing out the next 10 years to keep it small
// using a counter-controlled while loop
int count{10};
while(count > 0){
cout << static_cast<int>(currentYear) << "\t";
currentYear++;
count--;
}
cout << endl;

// printing out the anticipated population
// declaring the current population
float currentPop{81};
// declaring the anticipated population
float popResult;

// using counter controlled while loop to claculate
count = 10;
while (count > 0){
// calculating the percentage
popResult = currentPop + ((currentPop * rate)/100);
cout << popResult << "\t";
currentPop = popResult;
count--;
}
cout << endl;
}

0 comments on commit 8842b45

Please sign in to comment.