Write a program that illustrates the growth of the world's population using as input:
the start year
the initial population size
the annual percentage increase of the population
the end year.

You may assume that the input is valid.
Output the year, the size of the population and the population density every decade:
Surface area of a sphere is 4*π* R2
Earth’s radius [R] =3,984 miles
Fraction of surface which is land [F] = 0.29
π = PI = 3.14159

Use the total surface area of the earth (from given values for the Earth’s radius [R]) and the fraction
of the earth's surface which is land [F] to compute the land area. Specify the language used.

Initial Algorithm
CONSTANTS earth’s radius, PI, fraction of surface which is land
DECLARE necessary variables
CALCULATE the land area
INPUT the start year and the start population size
INPUT the annual percentage increase of the population
INPUT the end year
CALCULATE the annual growth rate
CALCULATE the number of decades (rounded up to the next highest integer)
CALCULATE initial population density {the initial population / land area}
PRINT headings
PRINT start year, initial population, initial population density
SET working population to the initial population size
FOR count = 1 TO number of decades DO
FOR inner count = 1 to 10 DO
CALCULATE the next working population {working population * growth
rate}

END FOR
CALCULATE the population density
UPDATE current year
PRINT current year, the working population and the population density
END FOR


-----------------below is the code i have done without errors i am stucj at the loop section----- please modify------------------

#include <iostream>
using namespace std;

int main()
{

double R=3984;
double PI=3.14159;
double F=0.29;
int start_year,end_year;
double an_pop_growth;
double start_pop_size;
cout <<" Welcome to the population growth calculation" <<endl;
cout <<"please enter start year: "<<endl;
cin>>start_year;
cout <<"please enter start population size: "<<endl;
cin>>start_pop_size;
cout <<" please enter end year: "<<endl;
cin>>end_year;
cout<<"please enter the annual percentage of population growth: "<<endl;
cin>>an_pop_growth;

double land_area=(4*PI*R*R)*0.29;
cout <<"land area of earth is: " <<land_area<<endl;
double an_growth_rate=an_pop_growth*start_pop_size;
cout<<"annual growth of population is: "<<an_growth_rate<<endl;
int num_decade=(end_year-start_year)/10;

double ini_pop_density=start_pop_size/land_area;
cout<<"Initial population density is : " <<ini_pop_density<<endl;







system("pause");
return 0;
}

Recommended Answers

All 3 Replies

You're stuck at the loop section? You don't HAVE a loop section. If you mean "I can't figure out how to CREATE the loop section", say that. Presumably you need help with this section?

FOR count = 1 TO number of decades DO
FOR inner count = 1 to 10 DO
CALCULATE the next working population {working population * growth
rate}

END FOR
CALCULATE the population density
UPDATE current year
PRINT current year, the working population and the population density
END FOR

C++ loop syntax would be like this:

int count, innerCount;

for(count = 1; count <= num_decade; count++)
{
    // code here if needed
    for(innerCount = 1; innerCount <= 10; innerCount++)
    {
       // code here
    }
    // code here if needed
}

Sorry my English is not always the best. Here is the new change to the code...no error in compilation but I am not getting exaxtly wat examiner asked for regarding the loop. but i think the examiner is a mad man for giving us questions like that a certificate level. please check it and modify where necessary for the final part of this question. many thanks.

#include <iostream>
using namespace std;

int main()
{

double R=3984;
double PI=3.14159;
double F=0.29;
int start_year,end_year;
double an_pop_growth;
double start_pop_size;
cout <<" Welcome to the population growth calculation" <<endl;
cout <<"please enter start year: "<<endl;
cin>>start_year;
cout <<"please enter start population size: "<<endl;
cin>>start_pop_size;
cout <<" please enter end year: "<<endl;
cin>>end_year;
cout<<"please enter the annual percentage of population growth: "<<endl;
cin>>an_pop_growth;

double land_area=(4*PI*R*R)*0.29;
cout <<"land area of earth is: " <<land_area<<endl;
double an_growth_rate=an_pop_growth*start_pop_size;
cout<<"annual growth of population is: "<<an_growth_rate<<endl;
int num_decade=(end_year-start_year)/10;

double ini_pop_density=start_pop_size/land_area;
cout<<"Initial population density is : " <<ini_pop_density<<endl;

double work_pop=start_pop_size;
int count, innerCount;
double  next_work_pop;
for(count = 1; count <= num_decade; count++)
{
    
    for(innerCount = 1; innerCount <= 10; innerCount++)
    {
     double  next_work_pop=work_pop*an_growth_rate;
    }
    int current_year = 2010;
    double current_pop_density=next_work_pop/land_area;
    cout<<" The current year is: " <<current_year<<endl;
    cout<<"The working population is: "<<next_work_pop<<endl;
    cout<<"The current population density is: " <<current_pop_density <<endl;
}




system("pause");
return 0;
}

Work a few out on paper first. The logic is all screwed up, in addition to the code. Line 27 is wrong. You are supposed to round UP, not down.


Do yourself a favor and declare ALL of your variables at the top. You have some unused ones. If you don't understand variable scoping yet, just stick them all at the top to be safe.

This looks incorrect in the instructions. Usually a population growth rate is defined as the population INCREASE, so if you go from 100,000 to 105,000 in a year, the growth rate would be 0.05, in which case this would be wrong.

FOR inner count = 1 to 10 DO
CALCULATE the next working population {working population * growth
rate}

This one doesn't make sense to me at all:

INPUT the annual percentage increase of the population
CALCULATE the annual growth rate

One of the basic fundamentals of population studies is that they generally grow geometrically. There IS no "annual growth rate" except for the annual percentage increase in population. So if I were you, I'd sit down with your professor and walk through a few calculations, completely independent of any programming language, particularly if you've never done this before. It seems like the outline is wrong to me. If you're familiar with these kind of calculations and the professor gave some sample input and ouput, you may be able to map your formulas to his, right or wrong. The professor is always right, as they say.

But if you don't understand the algorithm itself, you can't do the assignment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.