Answer to Question #336209 in C# for Siyanda

Question #336209

Write a program that requests the user for a year (you can assume the year will always be at


least 2000), the population of Brazil in that year (in terms of millions of people) and the annual


population growth rate (always as a real number in the range 0 – 1), and then uses the two


methods written above to determine and display the year in which Brazil’s population first


exceeded/exceeds 180 million people. The program must also display Brazil’s total population


in this year.



1
Expert's answer
2022-05-01T19:05:37-0400
namespace Population
{
    class Program
    {
        public static double PopulationTotal(double cur_pop, double gr_rate)
        {
            return (cur_pop + cur_pop * gr_rate);    
        }

        public static bool Over180Million(double pop)
        {
            if (pop > 180)
                return true;
            else
                return false;
        }
        
        public static void Main(string[] args)
        {
            int year, i;
            double population, popul_in_year, pop_gr_rate;
            Console.Write("Enter year: ");
            year = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter population of Brazil in {0} year (million): ", year);
            popul_in_year = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter annual population growth rate: ");
            pop_gr_rate = Convert.ToDouble(Console.ReadLine());
            population = PopulationTotal(popul_in_year, pop_gr_rate);
            for (i=year; Over180Million(population) == false; i++)
            {
                population += PopulationTotal(popul_in_year, pop_gr_rate);
            }
            Console.WriteLine();
            Console.WriteLine("The year in which Brazil’s population first exceeded/exceeds 180 million people: {0}" , i);
            Console.WriteLine("Brazil’s total population in {0} year: {1:f4} million people", i, population);

            
            Console.Write("\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS