a) Write a method PopulationTotal that accepts 2 positive values, namely the current
population (in millions, e.g. a value of 1.5 means 1.5 million people) and the growth rate (e.g.
0.14 means 14%). The method determines and returns the total population based on the current
population and growth rate. For example, if the current population for a country is 1.165 million
people, and the annual population growth rate is 10%, then the total population is 1.2815 million
people after 1 year.
b) Write a method Over180Million that accepts a positive value representing the population (in
millions). The method determines whether the population is over 180 million people, and returns
a value of true if this is so, otherwise returns a value of false.
internal class Program
{
static void Main(string[] args)
{
Console.Write("Enter number of people in millions:");
double people = double.Parse(Console.ReadLine());
Console.Write("Enter population growth rate:");
double populatationGrowRate = double.Parse(Console.ReadLine());
PopulationTotal(people, populatationGrowRate);
if (Over180Million(people))
Console.WriteLine("More than 180 million people in the country");
else
Console.WriteLine("There are less than 180 million people in the country");
Console.ReadKey();
}
static void PopulationTotal(double people,double rate)
{
people += people * (rate / 100);
Console.WriteLine($"Number of people in the country in a year {people} with population growth {rate}");
}
static bool Over180Million(double people)
{
if(people>=180)
return true;
return false;
}
}
Comments
Leave a comment