In: Computer Science
Write a C++ program that inputs the world's population at the end of last year. Assume population is growing at a rate of 1.12%.
Output the year (starting with this year) and the population until the population is greater than 10billion.
Test data: 6.83 billion. (leave like this rather than 6800000000).
Name as a comment and printed to output. Output as a comment at the bottom of the code
#include <iostream>
using namespace std;
int main()
{
double p,rate=1.12,total=0;
int y;
cout << "Enter worlds population in billion" <<
endl;
cin>>p;
cout << "Enter the year" << endl;
cin>>y;
while(total<10) // to check total population is less than 10
billion.
{
total=p+((1.12*p)/100);
p=total;
cout<<"year:"<<++y<< endl;
cout<<"Total population"<< p<<"billion"<<
endl;
}
return 0;
}
---------------------------------------------output----------------------------------------------------------------------------
Enter worlds population in billion
6.83
Enter the year
2011
year:2012
Total population :6.9065billion
year:2013
Total population :6.98385billion
year:2014
Total population :7.06207billion
year:2015
Total population :7.14116billion
year:2016
Total population :7.22114billion
year:2017
Total population :7.30202billion
year:2018
Total population :7.3838billion
year:2019
Total population :7.4665billion
year:2020
Total population :7.55013billion
year:2021
Total population :7.63469billion
year:2022
Total population :7.7202billion
year:2023
Total population :7.80666billion
year:2024
Total population :7.8941billion
year:2025
Total population :7.98251billion
year:2026
Total population :8.07192billion
year:2027
Total population :8.16232billion
year:2028
Total population :8.25374billion
year:2029
Total population :8.34618billion
year:2030
Total population :8.43966billion
year:2031
Total population :8.53418billion
year:2032
Total population :8.62977billion
year:2033
Total population :8.72642billion
year:2034
Total population :8.82415billion
year:2035
Total population :8.92299billion
year:2036
Total population :9.02292billion
year:2037
Total population :9.12398billion
year:2038
Total population :9.22617billion
year:2039
Total population :9.3295billion
year:2040
Total population :9.43399billion
year:2041
Total population :9.53965billion
year:2042
Total population :9.6465billion
year:2043
Total population :9.75454billion
year:2044
Total population :9.86379billion
year:2045
Total population :9.97426billion
year:2046
Total population :10.086billion