Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement a do-while loop to this solution below in C# language only private void btnCalculate_Click(object sender, EventArgs e) { //clear the items in the list

implement a do-while loop to this solution below in C# language only

private void btnCalculate_Click(object sender, EventArgs e) { //clear the items in the list box lstResult.Items.Clear(); //variable declarations double currentPopulation; int numberOfYears; double annualGrowthRate; //get the current population, if not valid display an error message if (Double.TryParse(txtCurrentPopulation.Text, out currentPopulation)) { //get the number of year, if not valid display an error message if (int.TryParse(txtNumberOfYears.Text, out numberOfYears)) { //get the annual growth rate, if not valid display an error message if (double.TryParse(txtAnnualGrowthRate.Text, out annualGrowthRate)) { //display the header for output lstResult.Items.Add("Year\tPopulation"); //get the current year int year = DateTime.Today.Year; //display the population in current year lstResult.Items.Add(year + "\t" + currentPopulation.ToString("0.00")); //run a loop for the number of years given for (int i = 0; i < numberOfYears; i++) { //compute the population currentPopulation = currentPopulation + (currentPopulation * annualGrowthRate / 100); //increment year year++; //display the population for each year lstResult.Items.Add(year + "\t" + currentPopulation.ToString("0.00")); } } //display error message if annual growth rate entered is invalid else { MessageBox.Show("Invalid input for annual growth rate."); txtAnnualGrowthRate.Focus(); } } //display error message if number of years entered is invalid else { MessageBox.Show("Invalid input for number of years."); txtNumberOfYears.Focus(); } } //display error message if current population entered is invalid else { MessageBox.Show("Invalid input for current population."); txtCurrentPopulation.Focus(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions