5.41 exercise Visual C#:How to Program (World Population Growth) World population has grown considerably over the centuries. Continued growth could eventually challenge the limits of
5.41 exercise Visual C#:How to Program (World Population Growth) World population has grown considerably over the centuries. Continued growth could eventually challenge the limits of breathable air, drinkable water, arable cropland and other limited resources. There's evidence that growth has been slowing in recent years and that world population could peak sometime this century, then start to decline. For this exercise, research world population growth issues online. Be sure to investigate various viewpoints. Get estimates for the current world population and its growth rate (the percentage by which it is likely to increase this year). Write a program that calculates world population growth each year for the next 75 years, using the simplifying assumption that the current growth rate will stay constant. When displaying the results, the first column should display the year from year 1 to year 75. The second column should display the anticipated world population at the end of that year. The third column should display the numerical increase in the world population that would occur that year. Using your result, determine the year in which the population would be double what it is today, if this year's growth rate were to persist. (Hint: Use double variables because int variables can store values only up to approximately two billion. Display the double values using the format F0, which displays the values rounded to the closest whole number - 0 means no digits to the right of the decimal point.)
This is the code I have which works, except for finding the year the population doubles. Please help me with that last part.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace Population { class Program { static void Main(string[] args) { // declare variables double currentPopulation = 7600000000; double growthRate = 0.0112; double newPopulation; double increase; int yearCounter = 1; int doubleYear = 0;
// print Header Console.WriteLine("Year\tPopulation\tIncrease");
// iterating for 75 years for (int i = 1; i <= 75; ++i) { // calculating new population newPopulation = currentPopulation + (currentPopulation * growthRate);
// calculating increase increase = newPopulation - currentPopulation;
// printing values Console.WriteLine($"{yearCounter}\t{currentPopulation:F0}\t{increase:F0}");
while (newPopulation == (currentPopulation * 2)) { doubleYear = i; }
// initialize variables currentPopulation = newPopulation;
}
Console.WriteLine($"Population will double in {doubleYear}"); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started